How can I use these JavaScript or jquery math functions ?
For example, I want to compute the sum of all values in a form, without submiting the form or in button click.
I have 4 input fields and i want to add then and put the result of them in another input or paragraph.
Html code looks like this :
<form id='myform'>
<label> Number 1 : </label><input value="" id="1"/><br>
<label> Number 2 : </label><input value="" id="2"/><br>
<label> Number 3 : </label><input value="" id="3"/><br>
<label> Number 4 : </label><input value="" id="4"/><br> <br>
<button href="#" class='add'> ADD</button>
<p id="p"> </p>
</form>
I tried to do something like this :
var one = $("#1").val();
var two = $("#2").val();
var three = $("#3").val();
var four = $("#4").val();
$("add").on("click", function(){
var sum = one + two + three + four;
$('p').text(sum);
})
I created a jsfiddle: example
Can you give a little help? Thank you.
onLoadas per jsfiddle defaults.OnloadoronDomReadyas I have seen questions like code running in fiddle but not in site etc