Firefox JavaScript Console Error: Form1 is not defined

J

Jon Natwick

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
 
M

Marina

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

bruce barker

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)




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

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top