I don't usually use js, so am hoping for a quick win. Although I can't find the answer on SO in spite of quite a few similar questions out there.
I have a form...
<input type=text size=5 id=value1 name=value1 />
<input type=text size=5 id=value2 name=value2 />
<input type=text size=5 id=total readonly=readonly class=bckground name=total />
How can I use ajax (or otherwise) to multiply value1 by value2 after their inputs have been entered, but before the form is submitted?
Requirement is to simply display a product of value1 * value 2 as the form is being filled out. But it would be nice to embed it to the form field, as above, in case I want to add it to my database.
Edit: Below is my attempt. But I can only get a span element to update, and not automatically. Also it fails if the fields are blank.
<script>
function calculateSum()
{
value1 = parseInt(document.getElementById(value1).value);
value2 = parseInt(document.getElementById(value2).value);
sum = value1 * value2;
document.getElementById(totalpledge).innerHTML = sum;
}
</script>
Seems to work with a button...
<input type=text size=5 id=value1 name=value1 />
<input type=text size=5 id=value2 name=value2 />
<span id=totalpledge>--</span>
<span><button onclick=calculateSum()>Submit!</button></span>