Perform math on dynamically updating javascript Value -
i have figured out how update html dynamically based on current input of form. however, stumped how perform math on value (ie value*5), , display result, instead of merely displaying value in form.
here live example: https://dl.dropboxusercontent.com/u/14749627/happy2/number.html
here javascript:
<script> window.onload = function() { var purchase_quantity = document.getelementbyid('purchase_quantity'); purchase_quantity.onclick = updatenamedisplay; purchase_quantity.onclick = updatenamedisplay; purchase_quantity.onclick = updatenamedisplay; function updatenamedisplay() { document.getelementbyid('namedisplay').innerhtml = this.value || "1"; } }; </script>
campari's solution works, should convert number explicitly habit. if tried add instead, wouldn't work expected. also, oriol pointing out other problem.
var purchase_quantity = document.getelementbyid('purchase_quantity'); purchase_quantity.onclick = updatenamedisplay; function updatenamedisplay() { document.getelementbyid('namedisplay').innerhtml = this.value.length ? number(this.value) * 5 : "1"; }
Comments
Post a Comment