Jump to content

Update sum using text feild


ferrit91

Recommended Posts

add an onchange=someFunction()  to your input field; in the function, calculate myNewValue (product, not sum!) and then post it to the field that you want it in with something like document.getElementById(yourSumFld) = myNewValue.  Try it and then come back with your code and questions.

I have this so far

 

<script type="text/javascript"><!--

 

function updatesum() {

document.form.sum.value = (document.form.sum1.value) * 1000;

}

 

//--></script>

 

<body>

 

<form name="form" >

Enter a number:

 

<input name="sum1" onkeydown="updatesum()" />

 

Their sum is:

 

<input name="sum" readonly style="border:0px;">

 

</form>

 

</body>

 

But when you put a number in it shows as 0 until you click off. I need it to show as they type

I'm guessing that the 'value' isn't posted until the value "changes".  YOu didn't say that you wanted this calc. to take place as you enter digits.  Doesn't make a lot of sense. 

 

In any case, you're going to have to handle keys that are not digits, as well as backspaces, deletes, escapes as well as 0-9.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.