I have this simple script, i want to multiply Var a * Var b then Multiply this by Var C with a set number eg 15.
But it doesn’t seem to work?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$('input[name="box2"]').keyup(function() {
var a = $('input[name="box1"]').val();
var b = $(this).val();
var c = $(15).val();
$('input[name="box3"]').val(a * b * c);
});
</script>
</head>
<body>
<input name="box1" type="text" /><br />
<input name="box2" type="text" /><br />
<input name="box3" type="text" />
</body>
A few changes to do :
Beware never never use parseInt without specifying the radix (
parseInt("09") is 0...).Another problem in your code is that you try to build your jquery collection before the dom is ready. Use this :
Note that it’s also best practice, especially when using jQuery which makes it easy, to have a script element at the end of the body to keep all the javascript that isn’t in separate files.