Small Java Script help

Discussion in 'ASP General' started by Prabhat, Sep 23, 2005.

  1. Prabhat

    Prabhat Guest

    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
    Prabhat, Sep 23, 2005
    #1
    1. Advertising

  2. 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.
    Dr John Stockton, Sep 23, 2005
    #2
    1. Advertising

  3. Prabhat

    Randy Webb Guest

    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
    Randy Webb, Sep 24, 2005
    #3
  4. Prabhat

    Randy Webb Guest

    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
    Randy Webb, Sep 24, 2005
    #4
  5. Prabhat

    Prabhat Guest

    >
    > 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
    Prabhat, Sep 25, 2005
    #5
  6. Prabhat

    Prabhat Guest

    > 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
    Prabhat, Sep 25, 2005
    #6
  7. JRS: In article <>, 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.
    Dr John Stockton, Sep 25, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. p byers

    A small script - Help Please

    p byers, Aug 12, 2007, in forum: ASP General
    Replies:
    0
    Views:
    97
    p byers
    Aug 12, 2007
  2. Matthew
    Replies:
    3
    Views:
    109
    Tintin
    Jan 19, 2004
  3. David

    HELP needed for a small script

    David, Jan 9, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    124
    Tad McClellan
    Jan 10, 2005
  4. David

    HELP needed for a small script

    David, Jan 9, 2005, in forum: Javascript
    Replies:
    1
    Views:
    85
    Dominic Myers
    Jan 9, 2005
  5. Replies:
    6
    Views:
    147
    Thomas 'PointedEars' Lahn
    Jan 7, 2009
Loading...

Share This Page