resetting values on blur
Closed this issue · 1 comments
vkd1980 commented
Hi,
I don't whether its an issue or my mistake. I am using calx for a form which populates values using ajaxx. My problem is when i click or infocus of populated textboxes , filled values are changing to zero and no calculation is happening ?
my code is given below which is using your sample
' . "\n"; } } closedir($handle); echo $css; } $js = ''; $handle = ''; $file = ''; // open the "js" directory if ($handle = opendir('includes/js')) { // list directory contents while (false !== ($file = readdir($handle))) { // only grab file names if (is_file('includes/js/' . $file)) { // insert HTML code for loading Javascript files $js .= '<script src="includes/js/' . $file . '" type="text/javascript"></script>' . "\n"; } } closedir($handle); echo $js; } ?> <title>Untitled Document</title> <script type="text/javascript"> ``` $(document).ready(function(){ $('#calx').calx({ autocalculate: false }); $('#calculate').click(function(){ $('#calx').calx('update'); }); }); function getbookvalues(isbn,isbnid) { isbnid=parseInt(isbnid.replace ( /[^\d.]/g, '' ),10); //var empcode = $("input[name='Emp_Code']:text").val(); ``` if(isbn==null || isbn==undefined || isbn==''){ ``` } else { $.ajax({ url: "includes/books_master.php?action=search", data: {"isbn":isbn}, type: 'post', dataType: "json", success: function(output) { var siteArray = output.array; if( !$.isArray(siteArray) || !siteArray.length ) { console.log(output); if (output[0]==0){ window.alert(output[2]); } else { $("#price"+isbnid).val(output[7]); $("#rate"+isbnid).val(output[6]); } } } }); } } </script>
</head>
<body>
<form id="calx">
<table>
<thead>
<tr>
<td style="width:250px">Item Name</td>
<td style="width:80px">Price</td>
<td style="width:30px">Qty</td>
<td style="width:30px">rate</td>
<td style="width:30px">Discount</td>
<td style="width:150px">Sub Total</td>
</tr>
</thead>
<tbody>
<tr>
<td><input id="item1" type="text" name="item[]" value="" onblur="getbookvalues(this.value,this.id)" /></td>
<td><input id="price1" type="text" name="price[]" value="" data-format="00.00" /></td>
<td><input id="qty1" type="text" name="qty[]" value="" data-format="0" /></td>
<td><input id="rate1" type="text" name="rate[]" value="" readonly="true" tabindex="-1" data-format="00.00" /></td>
<td><input id="disc1" type="text" name="disc[]" value="" data-format="0.00" /></td>
<td><input id="subtotal1" type="text" name="subtotal[]" value="" data-format="00.00" data-formula="($price1*$qty1)*($rate1)*(1-$disc1/100)" /></td>
</tr>
<tr>
<td><input id="item2" type="text" name="item[]" value="LCD Monitor BENQ 21"" /></td>
<td><input id="price2" type="text" name="price[]" value="250" data-format="$ 0,0[.]00" /></td>
<td><input id="qty2" type="text" name="qty[]" value="1" data-format="0" /></td>
<td><input id="disc2" type="text" name="disc[]" value="0.1" data-format="0.00 %" /></td>
<td><input id="subtotal2" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price2*$qty2)*(1-$disc2)" /></td>
</tr>
<tr>
<td><input id="item3" type="text" name="item[]" value="LiteOn DVD RW+" /></td>
<td><input id="price3" type="text" name="price[]" value="120" data-format="$ 0,0[.]00" /></td>
<td><input id="qty3" type="text" name="qty[]" value="1" data-format="0" /></td>
<td><input id="disc3" type="text" name="disc[]" value="0.2" data-format="0.00 %" /></td>
<td><input id="subtotal3" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price3*$qty3)*(1-$disc3)" /></td>
</tr>
<tr>
<td><input id="item4" type="text" name="item[]" value="MotherBoard Gigabyte G5-XXX" /></td>
<td><input id="price4" type="text" name="price[]" value="140" data-format="$ 0,0[.]00" /></td>
<td><input id="qty4" type="text" name="qty[]" value="1" data-format="0" /></td>
<td><input id="disc4" type="text" name="disc[]" value="0.05" data-format="0.00 %" /></td>
<td><input id="subtotal4" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price4*$qty4)*(1-$disc4)" /></td>
</tr>
<tr>
<td><input id="item5" type="text" name="item[]" value="PSU 600 Watt" /></td>
<td><input id="price5" type="text" name="price[]" value="30" data-format="$ 0,0[.]00" /></td>
<td><input id="qty5" type="text" name="qty[]" value="1" data-format="0" /></td>
<td><input id="disc5" type="text" name="disc[]" value="0" data-format="0.00 %" /></td>
<td><input id="subtotal5" type="text" name="subtotal[]" value="" data-format="$ 0,0[.]00" data-formula="($price5*$qty5)*(1-$disc5)" /></td>
</tr>
<tr>
<td><input id="calculate" type="button" value="calculate" /></td>
<td><input id="price_total" type="text" name="price_total" data-format="$ 0,0[.]00" data-formula="($price1+$price2+$price3+$price4+$price5)" /></td>
<td colspan="2">Total Price :</td>
<td><input id="total" type="text" name="total" value="" data-format="$ 0,0[.]00" data-formula="($subtotal1+$subtotal2+$subtotal3+$subtotal4+$subtotal5)" /></td>
</tr>
</tbody>
ikhsan017 commented
when you are changing the value of input that used by calx, try to trigger change event
$('some_input').val(someval).trigger('change');