i am wondering y doesnt show answer right away.

jmad

New Member
the script is set up for an onchange event but in order for it to work u need to leave the input field meaning its acting like it is an onblur event. y wont it change on the entery of new input? ne thoughts........???

<script language="JavaScript">

function calculate()
{
A1 = document.Qty_form.a1.value
A2 = document.Qty_form.a2.value
A3 = (A1*A2)
document.Qty_form.a3.value = A3
}
</script>

<html>
<body>

<form name="Qty_form">
<input type="text" name="a1">
X
<input type="text" name="a2" onChange=calculate();>
=
<input type="text" name="a3" >
</form>

<style type="text/css">
 
Last edited:

zkiller

Super Moderator
Staff member
1. add a semi-colon (;) at the end of each line within the function
2. might want to try declaring your variables as what they are. var A1, etc.

is A1 a set value?
 

jmad

New Member
still no good

is this what u meant i still have the problem with it seeming like it is on blur.
<html>
<body>


<script language="JavaScript">

function calculate()
{
A1 = document.Qty_form.quanity.value;
A2 = document.Qty_form.price.value;
A3 = (A1*A2);
document.Qty_form.total.value = A3;
}
</script>

<html>
<body>

<form name="Qty_form">
<input type="text" name="quanity">
X
<input type="text" name="price" onChange=calculate();>
=
<input type="text" name="total" >
</form>

<style type="text/css">

</body>
</html>
 
Last edited:

zkiller

Super Moderator
Staff member
something like that...

Code:
<html>
<body>


<script language="JavaScript">

function calculate()
{
var A1 = document.Qty_form.quanity.value;
var A2 = document.Qty_form.price.value;
var A3 = (A1*A2);
document.Qty_form.total.value = A3;
}
</script>

<html>
<body>

<form name="Qty_form" onChange=calculate();>
<input type="text" name="quanity">
X
<input type="text" name="price">
=
<input type="text" name="total" >
</form>

<style type="text/css">

</body>
</html>
seems to be working to me. you will need to finish the action of changing the respective value by either clicking out of the field or hitting enter.
 
Top