Firefox JavaScript Console Error: Form1 is not defined

Discussion in 'ASP .Net' started by Jon Natwick, Mar 1, 2005.

  1. Jon Natwick

    Jon Natwick Guest

    This "Countdown Timer" code works fine with Ie, but I receive an "Error:
    Form1 is not defined" error with Firefox 1.0.0 and 1.0.1.

    <body MS_POSITIONING="FlowLayout" onload="InitializeTimer()">
    <form name="Form1" method="post" action="test.aspx" id="Form1">

    <script language=JavaScript> var mins, secs, timerID = null, timerRunning =
    false, delay = 1000; function InitializeTimer() { mins = Form1.tbMins.value;
    secs = Form1.tbSecs.value; StopTheClock(); StartTheTimer(); } function
    StopTheClock() { if(timerRunning) clearTimeout(timerID); timerRunning =
    false; } function display(min, sec) { var disp; if(min<=9) disp=' 0'; else
    disp=' '; disp += min + ':'; if(sec<=9) disp += '0' + sec; else disp += sec;
    return(disp); } function decrement() { secs--; if(secs == -1) { secs = 59;
    mins--; } } function StartTheTimer() { if (mins == 0 && secs == 0) {
    document.Form1.hTimer.value = display(mins, secs); self.status =
    display(mins, secs); StopTheClock(); } else { document.Form1.hTimer.value =
    display(mins, secs); self.status = display(mins, secs); decrement();
    timerRunning = true; timerID = self.setTimeout('StartTheTimer()',
    delay); } } } </script>

    Any ideas??

    If I take out the Form1 prefix, it doesn't work in either Ie or Firefox.

    Thanks in advance,
    Jon
    Jon Natwick, Mar 1, 2005
    #1
    1. Advertising

  2. Jon Natwick

    Marina Guest

    Instead of 'Form1', try something like document.getElementById('Form1').
    Maybe store it in a local variable if you need it multiple times.

    "Jon Natwick" <> wrote in message
    news:zO1Vd.24193$-kc.rr.com...
    > This "Countdown Timer" code works fine with Ie, but I receive an "Error:
    > Form1 is not defined" error with Firefox 1.0.0 and 1.0.1.
    >
    > <body MS_POSITIONING="FlowLayout" onload="InitializeTimer()">
    > <form name="Form1" method="post" action="test.aspx" id="Form1">
    >
    > <script language=JavaScript> var mins, secs, timerID = null, timerRunning
    > = false, delay = 1000; function InitializeTimer() { mins =
    > Form1.tbMins.value; secs = Form1.tbSecs.value; StopTheClock();
    > StartTheTimer(); } function StopTheClock() { if(timerRunning)
    > clearTimeout(timerID); timerRunning = false; } function display(min, sec)
    > { var disp; if(min<=9) disp=' 0'; else disp=' '; disp += min + ':';
    > if(sec<=9) disp += '0' + sec; else disp += sec; return(disp); } function
    > decrement() { secs--; if(secs == -1) { secs = 59; mins--; } } function
    > StartTheTimer() { if (mins == 0 && secs == 0) {
    > document.Form1.hTimer.value = display(mins, secs); self.status =
    > display(mins, secs); StopTheClock(); } else { document.Form1.hTimer.value
    > = display(mins, secs); self.status = display(mins, secs); decrement();
    > timerRunning = true; timerID = self.setTimeout('StartTheTimer()',
    > delay); } } } </script>
    >
    > Any ideas??
    >
    > If I take out the Form1 prefix, it doesn't work in either Ie or Firefox.
    >
    > Thanks in advance,
    > Jon
    >
    >
    Marina, Mar 1, 2005
    #2
    1. Advertising

  3. Jon Natwick

    Wilco Bauwer Guest

    Wilco Bauwer, Mar 1, 2005
    #3
  4. Jon Natwick

    bruce barker Guest

    to access the form you can use

    any browser:

    document.Form1
    document.forms['Form1']
    document.forms[0] // if first or only form

    modern browsers

    document.getElementsByName('Form1')[0]
    document.getElementById('Form1') // requires id tag

    ie only:

    Form1
    document.all('Form1')


    -- bruce (sqlwork.com)




    "Jon Natwick" <> wrote in message
    news:zO1Vd.24193$-kc.rr.com...
    | This "Countdown Timer" code works fine with Ie, but I receive an "Error:
    | Form1 is not defined" error with Firefox 1.0.0 and 1.0.1.
    |
    | <body MS_POSITIONING="FlowLayout" onload="InitializeTimer()">
    | <form name="Form1" method="post" action="test.aspx" id="Form1">
    |
    | <script language=JavaScript> var mins, secs, timerID = null, timerRunning
    =
    | false, delay = 1000; function InitializeTimer() { mins =
    Form1.tbMins.value;
    | secs = Form1.tbSecs.value; StopTheClock(); StartTheTimer(); } function
    | StopTheClock() { if(timerRunning) clearTimeout(timerID); timerRunning =
    | false; } function display(min, sec) { var disp; if(min<=9) disp=' 0'; else
    | disp=' '; disp += min + ':'; if(sec<=9) disp += '0' + sec; else disp +=
    sec;
    | return(disp); } function decrement() { secs--; if(secs == -1) { secs = 59;
    | mins--; } } function StartTheTimer() { if (mins == 0 && secs == 0) {
    | document.Form1.hTimer.value = display(mins, secs); self.status =
    | display(mins, secs); StopTheClock(); } else { document.Form1.hTimer.value
    =
    | display(mins, secs); self.status = display(mins, secs); decrement();
    | timerRunning = true; timerID = self.setTimeout('StartTheTimer()',
    | delay); } } } </script>
    |
    | Any ideas??
    |
    | If I take out the Form1 prefix, it doesn't work in either Ie or Firefox.
    |
    | Thanks in advance,
    | Jon
    |
    |
    bruce barker, Mar 1, 2005
    #4
    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. Jon Natwick
    Replies:
    0
    Views:
    543
    Jon Natwick
    Mar 1, 2005
  2. Mr Newbie

    Page Controls - FindControl - Form1

    Mr Newbie, Sep 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,708
    Mr Newbie
    Sep 16, 2005
  3. SQwilDude
    Replies:
    1
    Views:
    400
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 14, 2007
  4. Oodini
    Replies:
    1
    Views:
    1,767
    Keith Thompson
    Sep 27, 2005
  5. jodleren

    form1.submit(); in Firefox? Works in IE

    jodleren, Mar 27, 2007, in forum: Javascript
    Replies:
    3
    Views:
    139
    Evertjan.
    Mar 27, 2007
Loading...

Share This Page