ferrit91 Posted June 25, 2012 Share Posted June 25, 2012 I want to add a part to my website where the sum shows next to a text field automatically and updates. So if i put 10 in the text field. The sum is to times it by 1,000 and the display would be 10,000. [10] 10,000 Quote Link to comment https://forums.phpfreaks.com/topic/264756-update-sum-using-text-feild/ Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2012 Share Posted June 25, 2012 Post the code you've tried so far. Quote Link to comment https://forums.phpfreaks.com/topic/264756-update-sum-using-text-feild/#findComment-1356888 Share on other sites More sharing options...
ferrit91 Posted June 25, 2012 Author Share Posted June 25, 2012 I haven't tried one yet. I'm not sure what it's called. Quote Link to comment https://forums.phpfreaks.com/topic/264756-update-sum-using-text-feild/#findComment-1356890 Share on other sites More sharing options...
ginerjm Posted June 25, 2012 Share Posted June 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/264756-update-sum-using-text-feild/#findComment-1356897 Share on other sites More sharing options...
ferrit91 Posted June 25, 2012 Author Share Posted June 25, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/264756-update-sum-using-text-feild/#findComment-1356904 Share on other sites More sharing options...
nogray Posted June 25, 2012 Share Posted June 25, 2012 try to change onkeydown to onkeyup or onkeypress Quote Link to comment https://forums.phpfreaks.com/topic/264756-update-sum-using-text-feild/#findComment-1356938 Share on other sites More sharing options...
ginerjm Posted June 26, 2012 Share Posted June 26, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/264756-update-sum-using-text-feild/#findComment-1356982 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.