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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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