Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Small Java Script help

Reply
Thread Tools

Small Java Script help

 
 
Prabhat
Guest
Posts: n/a
 
      09-23-2005
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


 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      09-23-2005
JRS: In article <#>, dated Fri, 23
Sep 2005 15:42:59, seen in news:microsoft.public.scripting.jscript,
Prabhat <> posted :
>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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      09-23-2005
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      09-23-2005
Dr John Stockton said the following on 9/23/2005 6:02 PM:

<snip>

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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
 
Reply With Quote
 
Prabhat
Guest
Posts: n/a
 
      09-25-2005
>
> 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


 
Reply With Quote
 
Prabhat
Guest
Posts: n/a
 
      09-25-2005
> 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


 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      09-25-2005
JRS: In article <bMudnRwast6JDqneRVn->, dated Fri, 23 Sep
2005 19:43:22, seen in news:microsoft.public.scripting.jscript, Randy
Webb <> posted :
>Dr John Stockton said the following on 9/23/2005 6:02 PM:
>
><snip>
>
>> 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.


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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Small and Easy Java Script-Checkboxes Problem franklembke@googlemail.com Javascript 6 01-07-2009 06:01 PM
A small script - Help Please p byers ASP General 0 08-12-2007 09:08 AM
Small cameras getting too small? GRL Digital Photography 50 02-03-2006 03:12 AM
Small Square with small red X Peter Coddington Computer Support 4 01-03-2006 06:58 AM
Need help with a small Perl script to display red screen Matthew Perl Misc 3 01-19-2004 08:19 AM



Advertisments