dwperry1 Posted February 5, 2012 Share Posted February 5, 2012 This might be a javaScript question, but I am sending entries from a form via PHP to a MySQL db. Sometimes I beed to be able to enter a negative numeric value (-56.00, or -.63) but I can't seem to find a way to calculate any of these fields without the negative numbers being surrounded in brackets '()' and the result displaying 'NAN' in the total fields. Any ideas? Thanks for your help! Doug Code: function calcincome(form, elemName, ttl) { form.currency_total.value = Fix(eval(form.currency_am.value-0) + (form.currency_pm.value-0)); } <form name="smartform"> <input type="text" name="currency_am" value="" id="currency_am" onChange="calcincome(this.form,'currency_am','Currency for Day Shift'); formatNumber(this, 2);" /> <input type="text" name="currency_pm" value="" id="currency_pm" onChange="calcincome(this.form,'currency_pm','Currency for Day Shift'); formatNumber(this, 2);" /> <input type="text" name="currency_total" value="" onChange="this.form.currency_am.value + this.form.currency_pm.value; calcincome(this.form,'field'); formatNumber(this, 2);" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/256428-allow-calculating-negative-numbers-in-form-fields/ 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.