How do I multiply the number that is put into my input using Javascript?
This is a total beginner question – you are a good person for helping.
html
<input type="number" id="height" value="0" />
javascript
$(document).ready(function() {
function display_height() {
var new_height = $("#height").val() * 3);
$("new_height").show();
});
});
There is no
showmethod on a string. Try alerting your height instead:Additionally, you had minor problems like mismatched parentheses and braces, which I have corrected.
What I suspect you actually want is for the user to be able to multiply input, in which case you need a button:
and a click handler:
You can see a demonstration here: http://jsfiddle.net/4wgaE/1/
To parse a string to a number, use
parseFloatlike this: