You need to put a space in front of the word selected. Right now your HTML
output will contain:

<option value=2005selected>2005</option>

This makes the value equal to 2005selected. By putting a space in between
the quote and the word selected - you will change the value to 2005 and
selected will be picked up correctly.

document.write('<option value=' + i + ' selected>' + i + '</option>');

You should put double quotes around the value parameter - its cleaner HTML:

document.write('<option value="' + i + '" selected>' + i + '</option>');

You might have to escape those - I'm not sure.

-----Original Message-----
From: Jacob Wilson [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 04, 2003 5:00 PM
To: Struts Users Mailing List
Subject: RE: Javascript question... 

Richard...
 
I find this list to be more user friendly in terms of responding to
questions... Also, not that I do not use Struts at all... for this
particular requirement of an old project under maintenance, I am trying to
do this... I consider this to be very much knowledge sharing list and hence
post questions whenever I have any... thanks is advance...
 
Now, getting back to your question... this is the code...
 
<script language="javascript">
 function generateYear(optionName,defaultValue) {
  var today = new Date();
  var year = today.getYear();
  document.write('<select NAME='+optionName+'>');
  document.write('<option value="year">Year</option>');
  for (var i=(year-4);i<(year+4);i++ ) {
   if(defaultValue == i) {
    document.write('<option value=' + i +'selected>' + i+'</option>');
   } else {
    document.write('<option value=' + i +'>' + i+'</option>');
   }
  }
document.write('</select>');
 }

<html>
<script language="javascript">
 generateYear("optStartDtYear",2005);
</script>
</html>
 
My idea is to make '2005' selected when the page loads... The above code
fails to make '2005' selected!!! If you can make me know the reason, it'd be
great... Thanks! 

"Yee, Richard K,,DMDCWEST" <[EMAIL PROTECTED]> wrote:
Jacob,
You wrote: "unfortunately we aren't using Struts here..."?
If you aren't using Struts then
a) why are you asking this question on a Struts mailing list
b) What do you mean then when you write "Now if I have values of day, month,
year executing an action. How can I default those values in the select
box???"

Regards,

Richard


---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

Reply via email to