...

View Full Version : why won't this work? - document.test.area.value -



Coastal Web
03-25-2005, 07:32 PM
Hello everyone,l was hoping someone could tell me why either of the following functions do not work:


<script>
function test(){
alert(document.break.time.value);
}
</script>


<script>
function test2(){
c = document.break.time.value;
alert(c);
}
</script>

<form name="break">
<input name="time" type="text" size="5" value="0">
</form>

<br><br>
<a href="javascript:test()">TEST1</a>
<br>
<a href="javascript:test2()">TEST2</a>

This is something that happens to me *all the time* and l can't figure it out.. l just end up re-writing the script until it works.. but l honestly can't figure out what the problem is.. can anyone help me please?

Thanks

Samantha Gram.

Coastal Web
03-25-2005, 07:35 PM
Now here's something that really trips me out -- l just changed

the form name to "b" (instead of "break");
and the code seem'd to work...

however if l change the form name to "brk" and the input name to "tm" it doesn't work...

as in:






<script>

function break_time(){

alert(document.brk.tm.value);

}
break_time();
</script>


<form name="brk">
<input name="tm" type="text" size="5" value="0">
</form>


Samantha Gram.

mcdougals4all
03-25-2005, 07:41 PM
As you've seen, break is a reserved word...

http://javascript.about.com/library/blreserved.htm

Willy Duitt
03-25-2005, 07:42 PM
http://www.scsite.com/js/qr.cfm

Mr J
03-26-2005, 02:05 PM
The way you have this set out




<script>

function break_time(){

alert(document.brk.tm.value);

}
break_time();
</script>


<form name="brk">
<input name="tm" type="text" size="5" value="0">
</form>



the script runs before the form has loaded and will produce an error

You should use onload=break_time in the script or move break_time() to the opening body tag.

<BODY onload="break_time()">

Coastal Web
03-27-2005, 06:46 PM
Thank you Mr J for your help!!


As the other two people had replied (thank you as well) however if you would have read my posts you'd have seen that using a reserved word wasn't my problem - as l'd change the "break" to "b" for the name of the form element..

2ndly - l wasn't using a reserved word to name a variable... But thanks for trying as they say lol.

Samantha Gram.

Willy Duitt
03-27-2005, 06:58 PM
Last edited by Samantha Gram : 03-25-2005 at 07:42 PM.
(this reflects my timezone, yours may vary)

And if you return and read your post again you will find that you returned and editted your post AFTER myself and mcdougals4all had replied... So thank yourself for any confusion and/or misunderstanding... :rolleyes:

.....Willy

Willy Duitt
03-27-2005, 07:20 PM
BTW: In the event you misunderstood my previous post...

Let me try to explain it again...
Just because you return and edit your post and change the goal line so to speak...
Do not expect us to return and edit our posts to answer your additional questions...

Good thing the forum software adds the editted notice or you would have us looking like idiots by changing your post after we responded to your original post... :mad:
.....Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum