javascript - Copy value from one form field into another without checkbox -
i'd enter number form field , have field next automatically update 2x number. can't figure out how without checkbox.
i have this:
var val = document.form1.field1.value   if (/^\s*$/.test(val)) {   }   else {     document.form1.field2.value = val * 2   } what thought check if field1 has value (otherwise i'd fields show placeholder), , if have value make field2 = field1 * 2
my goal have field2 update type numbers in field1.
thank help!
add keyup handler, , parse value number (it's string) , multiply 2 :
<form id="form1">     <input id="field1" onkeyup="fn(this)" />     <input id="field2" /> </form>  <script type="text/javascript">     function fn(elem) {         var val = parsefloat(elem.value) * 2 || '';         document.getelementbyid('field2').value = val;     } </script> 
Comments
Post a Comment