kpetsche20 Posted October 23, 2008 Share Posted October 23, 2008 I have a form, it allows a person to add 3 products, each form has a different value. I want to add those values together before the form submits. Link to comment https://forums.phpfreaks.com/topic/129862-how-do-you-add-form-field-values-together-before-the-form-is-submitted/ Share on other sites More sharing options...
F1Fan Posted October 23, 2008 Share Posted October 23, 2008 In your JS validation function, add the values together and put the sum in a hidden input. Link to comment https://forums.phpfreaks.com/topic/129862-how-do-you-add-form-field-values-together-before-the-form-is-submitted/#findComment-673259 Share on other sites More sharing options...
kpetsche20 Posted October 23, 2008 Author Share Posted October 23, 2008 I'm pretty new to JS I don't know what to code and where to put it. Link to comment https://forums.phpfreaks.com/topic/129862-how-do-you-add-form-field-values-together-before-the-form-is-submitted/#findComment-673269 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2008 Share Posted October 23, 2008 I would do any addition on the server in the form processing code. If you are adding numbers in the browser and you are depending on the value to be accurate, you will find that there are a lot of people who would submit incorrect information in order to pay a lower price for something or to cheat at games.... Link to comment https://forums.phpfreaks.com/topic/129862-how-do-you-add-form-field-values-together-before-the-form-is-submitted/#findComment-673276 Share on other sites More sharing options...
kpetsche20 Posted October 24, 2008 Author Share Posted October 24, 2008 I have php code setup to detect fraudulent users, I just want it as a convenience factor for signups Link to comment https://forums.phpfreaks.com/topic/129862-how-do-you-add-form-field-values-together-before-the-form-is-submitted/#findComment-673314 Share on other sites More sharing options...
F1Fan Posted October 24, 2008 Share Posted October 24, 2008 JS: function validateForm(){ var val1 = parseInt(document.getElementById('firstinput').value,10); var val2 = parseInt(document.getElementById('secondinput').value,10); var val3 = val1+val2; document.getElementById('thirdinput').value = val3; } HTML: <input type="text" name="firstinput" id="firstinput"> <input type="text" name="secondinput" id="secondinput"> <input type="hidden" name="thirdinput" id="thirdinput"> <input type="submit" value="Submit" onclick="return validateForm();"> Link to comment https://forums.phpfreaks.com/topic/129862-how-do-you-add-form-field-values-together-before-the-form-is-submitted/#findComment-673698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.