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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.