Try this simple...

        document.write('<select NAME='+optionName+'>');
        document.write('<option value="year">Year</option>');
        for (var i=(year-4);i<(year+4);i++ ) {
                document.write('<option value=' + i +'>' + i+'</option>');
                if(i==defaultValue) {
                        document.write('<option value="' + i + '" selected>' + i + 
'</option>');
                 }
        }
        document.write('</select>');

-Ram


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


Ohhhhh... thanks buddy... I actually created an option object and finished this... 
After you saying I checked and yes how stupid I am !!! simple mistakes need an other 
eye... Thanks again...
 
I did something like this -- this works fine too...
 
var s = document.forms[0];
 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) {
    yearOption = new Option();
    yearOption.text= i; 
    yearOption.value= i; 
    s.elements[optionName].options[s.elements[optionName].options.length]=yearOption; 
    yearOption.selected = true;
   } else {
    document.write('<option value='+i+'>'+i+'</option>');
   }
  }
  document.write('</select>');
 }

Joe Krause <[EMAIL PROTECTED]> wrote:
You need to put a space in front of the word selected. Right now your HTML
output will contain:

2005

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('' + i + '');

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

document.write('' + i + '');

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...


 function generateYear(optionName,defaultValue) {
  var today = new Date();
  var year = today.getYear();
  document.write('');
  document.write('Year');
  for (var i=(year-4);i   if(defaultValue == i) {
    document.write('' + i+'');
   } else {
    document.write('' + i+'');
   }
  }
document.write('');
 }



 generateYear("optStartDtYear",2005);



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" 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


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

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to