Jump to content

Allow calculating negative numbers in form fields


dwperry1

Recommended Posts

 

 

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>

 

Archived

This topic is now archived and is closed to further replies.

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