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 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. 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. 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. 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 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 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. 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
Archived
This topic is now archived and is closed to further replies.