opencart - Remove onKeyup Event handler on input fields -


i have form on admin panel of opencart work out total product costs , break down cost.

i have 3 editable fields , total field.

the whole inputs worked out onkeyup (this built developer)

i've made buttons autofill fields data, way coded, works out total onkeyup, means if click button auto fill data, still have click field , press button (usually enter) update total field.

is there event handle work out on fly, removing onkeyup function , working out total dont need click box after ive pressed button?

<table border="0" cellspacing="0" cellpadding="0">   <tr>     <td nowrap="nowrap"><input onkeyup="totalcost(this.form);" type="text" name="cost" value="<?php echo $cost; ?>" style="text-align:right; background-color: #ffd7d7; border: thin solid #999;" /></td>     <td width="40" align="center" nowrap="nowrap">=</td>     <td nowrap="nowrap"><input onkeyup="totalcost(this.form); if(!this.value) this.value=0; totalcost(this.form);" id="cog" type="text" name="cost_amount" value="<?php echo $cost_amount; ?>" style="border: thin solid #999;" /></td>     <td width="50" align="center" nowrap="nowrap"><?php echo $text_cost_or; ?></td>     <td nowrap="nowrap"><input onkeyup="totalcost(this.form); if(!this.value) this.value=0; totalcost(this.form);" id="perc" type="text" name="cost_percentage" maxlength="5" value="<?php echo $cost_percentage; ?>" style="border: thin solid #999;" />%</td>     <td width="40" align="center" nowrap="nowrap">+</td>     <td nowrap="nowrap"><input onkeyup="totalcost(this.form); if(!this.value) this.value=0; totalcost(this.form);" id="podf" type="text" name="cost_additional" value="<?php echo $cost_additional; ?>" style="border: thin solid #999;" /></td>     <td width="40" align="center" nowrap="nowrap">+</td>     <td nowrap="nowrap" align="left"><div id="tabs"><a href="#tab-option"><?php echo $text_cost_option_cost; ?></a></div></td>       </tr>   <tr>     <td align="center" nowrap="nowrap"><span class="help"><?php echo $text_cost; ?></span></td>     <td>&nbsp;</td>     <td align="center" nowrap="nowrap"><span class="help"><?php echo $text_cost_amount; ?></span></td>     <td>&nbsp;</td>     <td align="center" nowrap="nowrap"><span class="help"><?php echo $text_cost_percentage; ?></span></td>     <td>&nbsp;</td>     <td align="center" nowrap="nowrap"><span class="help"><?php echo $text_cost_additional; ?></span></td>     <td>&nbsp;</td>     <td align="left" nowrap="nowrap"><span class="help"><?php echo $text_cost_option; ?></span></td>       </tr>    <tr>     <td>         <input type="button" value="pod" id="pod" />         <input type="button" value="stk" id="stk" />          <script>             $(function () {             $('#pod').on('click', function () {                 var text = $('#perc');                 text.val(0);                  var text = $('#cog');                 text.val(1.55);                    var text = $('#podf');                 text.val(3.10);                 });              $('#stk').on('click', function () {                 var text = $('#perc');                 text.val(15);                  var text = $('#cog');                 text.val(0);                   var text = $('#podf');                 text.val(0);                 });            });          </script>      </td>   </tr>     </table> 

all need in code call totalcost() function after setting values after button click. let's assume <form> has id form, this:

<script type="text/javascript">     $(function () {         $('#pod').on('click', function () {             var text = $('#perc');             text.val(0);             var text = $('#cog');             text.val(1.55);             var text = $('#podf');             text.val(3.10);              totalcost($('#form'));         });          $('#stk').on('click', function () {             var text = $('#perc');             text.val(15);             var text = $('#cog');             text.val(0);             var text = $('#podf');             text.val(0);             text.val(3.10);              totalcost($('#form'));         });     }); </script> 

note added calls totalcost() passing <form id="form"> selector. if form has different id (or not have id @ all) make sure adjust selector (or <form> well).


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -