javascript - jQuery bind on keypress not firing -


i trying bind keypress , change of form values update function end user can see effect of updates real time. reason not firing @ all.

html

<fieldset class="iops-field">     <legend>iops/bandwidth</legend>     <table>         <tr>             <td>                 <input type="radio" name="bandwidth" value="iops-block" checked>iops @ block size:             </td>             <td>                 <input type="text" name="iops" id="iops" value="500000" size="3"> @                 <select id="block-size">                     <option value="4096" selected>4k</option>                     <option value="8192">8k</option>                     <option value="16384">16k</option>                     <option value="32786">32k</option>                     <option value="65536">64k</option>                 </select>             </td>         </tr>         <tr>             <td>                 <input type="radio" name="bandwidth" value="pure-bandwidth">bandwidth (gbps):             </td>             <td>                 <input type="text" name="bandwidth-entry" value="1953.125" id="bw" size="6">             </td>         </tr>     </table> </fieldset> 

jquery/javascript

function iops_bw_update(toupdate) {         var iops = parseint($("#iops").val());         var block = parseint($("#block-size").val());         var bw = parsefloat($("#bw").val());          if (toupdate == "bw") {             $("#bw").val((iops*block)/1048576);         }         else {             $("#iops").val((bw*1048576)/block);         } }  $(document).ready(function(){         $("#iops").bind("keypress", iops_bw_update("bw"));     $("#bw").bind("keypress", iops_bw_update("iops"));     $("#block-size").bind("change", iops_bw_update("bw")); }); 

you need pass function ref instead of passing value of function.

$("#iops").bind("keypress", your_function); // note: no () when no params need passed! 

the correct way of binding handler params is:

$(document).ready(function(){         $("#iops").bind("keypress", function() {         iops_bw_update("bw");     });     $("#bw").bind("keypress", function() {         iops_bw_update("iops");     });     $("#block-size").bind("change", function() {         iops_bw_update("bw");     }); }); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -