javascript - How to use value in input type number for calculate and set value in to other input? -


how use value in input type number calculate , set value in other input ?

when fill value input id xxx case fill 5 want use value multiple 3 , value 15 input id yyy

how can ?

<p>  <input name="xxx" type="number" id="xxx" onkeydown="return isnumber(event)">  </p>    <p>  <input name="yyy" type="number" id="yyy"  disabled >  </p>      <script>  function isnumber(number_check) {      number_check = (number_check) ? number_check : window.event;      var charcode = (number_check.which) ? number_check.which : number_check.keycode;      if (charcode > 31 && (charcode < 48 || charcode > 57)) {          return false;      }      return true;  }  </script>

since input #xxx type number, don't need return false value isn't number... can't happen.

so have value , parse integer (the value type of input text) perform math operations on it.

then, right events keyup, more keydown (since value isn't yet in field @ moment) or on change.

$("#xxx").on("keyup change", function(){    $("#yyy").val( parseint($("#xxx").val())*3 );  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <p>  <input name="xxx" type="number" id="xxx">  </p>    <p>  <input name="yyy" type="number" id="yyy" disabled >  </p>


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -