Small Java Script help

P

Prabhat

Hi All,

I have one .ASP file where a small java script is integrated and the output
does work in IE but not in FireFox or Opera 8.5. Please suggest.

Code:

<form name="test">
<select name="GraduationYr" >
<option value="-1"></option>
<script language="JavaScript">
var today= new Date();
var ayear = today.getYear();
for(i=ayear;i>1930;i--)
{
var newOptions = new Option();
newOptions.value = i;
newOptions.text = i;

document.all.GraduationYr.options[document.all.GraduationYr.options.length]
= newOptions;
if (i == 0)

document.all.GraduationYr.options[document.all.GraduationYr.options.length-1
].selected = true;
}
</script>
</select>


Thanks
Prabhat
 
D

Dr John Stockton

JRS: In article <#[email protected]>, dated Fri, 23
Sep 2005 15:42:59, seen in
Prabhat said:
I have one .ASP file where a small java script is integrated and the output
does work in IE but not in FireFox or Opera 8.5. Please suggest.

You should describe the nature of the failure - what you expect it to do
and what, if anything, it does.

<form name="test">
<select name="GraduationYr" >
<option value="-1"></option>
<script language="JavaScript">
var today= new Date();
var ayear = today.getYear();

For years 1900 to 1999, getYear() returns 0 to 99. For later years, it
may return 2000..., 100..., or 0....

If you can assume a sufficiently recent browser, use getFullYear()
instead; otherwise use (till 2100) 2000 + getYear()%100 or my function
getFY() in <URL:http://www.merlyn.demon.co.uk/js-date0.htm#gFY>.

However, given the inadequacy of your description, I cannot say whether
that is the cause of what you observe. However, your code does
something reasonable on my system, for which getYear() currently gives
2005, and does not if I sabotage getYear().

ISTM that starting at 1930 is inadequate, or discriminatory against aged
intellectuals.
 
R

Randy Webb

Prabhat said the following on 9/23/2005 6:12 AM:
Hi All,

I have one .ASP file where a small java script is integrated and the output
does work in IE but not in FireFox or Opera 8.5. Please suggest.

Stop using the IE-only document.all syntax would be a start to getting
it to work in any non-IE browser.
Code:

<form name="test">
<select name="GraduationYr" >
<option value="-1"></option>
<script language="JavaScript">
var today= new Date();
var ayear = today.getYear();
for(i=ayear;i>1930;i--)
{
var newOptions = new Option();
newOptions.value = i;
newOptions.text = i;

document.all.GraduationYr.options[document.all.GraduationYr.options.length]
= newOptions;

But it seems that GraduationYr is the Select object? If so, then you
need to access it using the forms collection. See

http://jibbering.com/faq/#FAQ4_13


That may not be all, and without seeing your HTML it is impossible to tell.
 
R

Randy Webb

Dr John Stockton said the following on 9/23/2005 6:02 PM:

ISTM that starting at 1930 is inadequate, or discriminatory against aged
intellectuals.

Graduate in 1930, start school in 1918 assuming a true 12 year
education. Giving the benefit of the doubt and assuming they started
school at 5, that would make them born in 1913 or so. That would put
them at approximately 92 years old. 92 year old "intellectual"s are too
happy to be alive to be worried about a website.
 
P

Prabhat

However, given the inadequacy of your description, I cannot say whether
that is the cause of what you observe. However, your code does
something reasonable on my system, for which getYear() currently gives
2005, and does not if I sabotage getYear().

Hi,

I wanted to load the drop down box with one empty value and other values
from 1931 to current year.

Thanks
Prabhat
 
P

Prabhat

But it seems that GraduationYr is the Select object? If so, then you need
to access it using the forms collection. See

http://jibbering.com/faq/#FAQ4_13

Hi,

Thanks for the link. Using that code I am trying to add year values to the
drop down options which is "one empty value" and other values from 1931 to
current year.

Thanks
Prabhat
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Fri, 23 Sep
2005 19:43:22, seen in Randy
Webb said:
Dr John Stockton said the following on 9/23/2005 6:02 PM:



Graduate in 1930, start school in 1918 assuming a true 12 year
education. Giving the benefit of the doubt and assuming they started
school at 5, that would make them born in 1913 or so. That would put
them at approximately 92 years old. 92 year old "intellectual"s are too
happy to be alive to be worried about a website.

Bertrand Russell (1872-1970) was active into at least his mid-nineties.
George Bernard Shaw (1856-1950) was active into at least his nineties.
So was my late colleague PV.
Other examples can be found in the Obituaries of learned societies
My oldest relative is over 93 and still active enough to be capable of
such concern.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top