We are using the following fields to calculate some.
$ (document) .ready (Function () {$ ('.num'). Blurring (function () {var amount = parseint ($ ('# zodiac'). Val ( )) | Var openbal = parseInt ($ ('# openbal' ') .val ()); var disk = parseInt ($ (' # disk '). Val ()); var netpay = fees + open-cart || 0; $ ('#netpay'). Val (netpace);});}); And here is the html code
& lt; Select name = "product" category = "product" & gt; & Lt; Option selected & gt; Select a product & lt; / Options & gt; & Lt; Options & gt; Product 1 & lt; / Options & gt; & Lt; Options & gt; PRODUCT2 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Input type = "text" size = "30" name = "zodiac" square = "number" id = "zodiac" /> & Lt; Input type = "text" class = "num" name = "openbal" value = "0" id = "openbal" /> & Lt; Input type = "text" class = "number" name = "disk" value = "0" id = "disc" /> & Lt; Input type = "text" name = "netpay" id = "netpay" /> So what we are doing here ...
- Choose the product from the drop down list and get the amount using the AJAX (#z).
- We are calculating using the given discount or any pending balance like .inum (class)
Our code is working fine, but it is only updated Netpay (#netpay) when we blur on any .num field and update this calculation. For example, we (#disc) give 500 discounts, netpay (#nnetpace), but if we update any number (.num) field, we want to calculate it after its price and netpay (#NETPAY).
The easiest way would be to set the value for #amount Strong> Increase the blur event . Then handler for your success Ajax call, do something like this: $ ('# zodiac)'. Val ('newValue'). Blur (); As the Blurring event handler is also bound to #amount , it will be executed by raising this incident (but you Anyone else can use
Unfortunately, setting the value of a text input element with .val () No boosts changes event.
Further comment: If you Use the parseInt , make sure you have the second parameter Please pass the correct radix in the form so it should be parseInt ($ ('(' # sum '). Val (), 10) Otherwise, if a number inputs with a leading 0s, then the value Is parsed as octal value, if the value is a simple number without any suffix, then you should code + : var amount = + $ ( '# Zodiac') .val () || 0, OpenBill = + $ ('# OpenBall'). Val () || 0, Disk = + $ ('# Disk'). Val () || 0, Netpace = Fees + Openbill - Disks; $ ('# Netpay') Val (Netpay).
Comments
Post a Comment