Thread View: comp.lang.javascript
2 messages
2 total messages
Started by Tor-Arne Bertheussen
Mon, 20 Mar 2000 00:00
Formfield validation problems
Author: Tor-Arne Bertheussen
Date: Mon, 20 Mar 2000 00:00
Date: Mon, 20 Mar 2000 00:00
61 lines
2660 bytes
2660 bytes
I feel completely lost and hope somebody could help me out on this.
What I'm trying to do is to make the user of a form select some values
from a number of drop-down lists. The sum of all the values is supposted
to be added and presented in a textfield that cannot be edited manually.
Each time the user choose a value from one of the lists the sum is
recalculated and presented in the text-field.
I have gotten my JavaScript to work fine in Internet Explorer, but not
in Netscape (ver.4.7). I have attacted my code below.
For some reason the result of eval(document.theForm.q2n.value) is always
"null". I have also tried to include eval(myForm.q2n.value) to see if
this gives any other result - with no lucky.
Does anyone know how this problem can be solved?
TIA
Tor-Arne
--------------------------------- Code
------------------------------------
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
function Calculate(myForm)
{
total = 0 ;
n = eval(myForm.q2n.value) ;
document.theForm.sum.value = eval(document.theForm.q2n.value) ;
// alert(document.theForm.q2n.value + ", " + n + ", " + total) ;
// document.theForm.sum.value = total ;
}
</SCRIPT>
</HEAD>
<BODY>
<p>
<form name="theForm" method="POST" action="">
<select name="q2n" size="1" onChange="Calculate(this.form);">
<option value="0">0%</option>
<option value="10">10%</option>
<option value="20">20%</option>
</select>
<p>Sum: <input type="text" name="sum" size="3" onFocus="this.blur()">
<p><input type="submit" value="Continue" name="Continue"></p>
</form>
</BODY>
</HTML>
Re: Formfield validation problems
Author: Lee
Date: Mon, 20 Mar 2000 00:00
Date: Mon, 20 Mar 2000 00:00
56 lines
2446 bytes
2446 bytes
Tor-Arne said:
>
>I feel completely lost and hope somebody could help me out on this.
>
>What I'm trying to do is to make the user of a form select some values
>from a number of drop-down lists. The sum of all the values is supposted
>to be added and presented in a textfield that cannot be edited manually.
>Each time the user choose a value from one of the lists the sum is
>recalculated and presented in the text-field.
>
>I have gotten my JavaScript to work fine in Internet Explorer, but not
>in Netscape (ver.4.7). I have attacted my code below.
>
>For some reason the result of eval(document.theForm.q2n.value) is always
>"null". I have also tried to include eval(myForm.q2n.value) to see if
>this gives any other result - with no lucky.
>
>Does anyone know how this problem can be solved?
>
>TIA
>
>Tor-Arne
>
>--------------------------------- Code
>------------------------------------
>
><HTML>
><HEAD>
><TITLE></TITLE>
><SCRIPT LANGUAGE="JavaScript">
>
>function Calculate(myForm)
>{
> total = 0 ;
> n = eval(myForm.q2n.value) ;
>
> document.theForm.sum.value = eval(document.theForm.q2n.value) ;
>
>// alert(document.theForm.q2n.value + ", " + n + ", " + total) ;
>// document.theForm.sum.value = total ;
>
>}
See http://www.azphx.com/dhtml/select.html
Here's a function that should work in both browsers as well as yours
does in IE, but neither version correctly handles the case of a user
changing a selection. For that, you either need to remember each
previous setting or re-total all of your Select objects whenever any
of them is changed.
function Calculate(myForm)
{
myForm.sum.value+=parseInt(myForm.q2n.options[myForm.q2n.selectedIndex].value);
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads