Jump to content

"onchange" calculation in HTML Form


dstafford

Recommended Posts

Sorry all...nubie question. Just getting into scripting in HTML pages and I am running into a brick wall.I have a simple form that have 4-5 text input boxes that go to a database, however I would like the form to display a "running total" box. The form handles some hours that people spend on some projects and I would like to show the total as they update each days' time. I know I need to utilize the onchange property somehow but I am not grasping the concept of how to pass the current value to the function and keep the total updated.Any assitance would be appreciated.Thanks

Link to comment
Share on other sites

here is a rough layout

<input type="text" name="field1" id="field1" onblur="calculate()" /><input type="text" name="field2" id="field2" onblur="calculate()" /><input type="text" name="field3" id="field3" onblur="calculate()" /><input type="text" name="field4" id="field4" onblur="calculate()" /><input type="text" name="field5" id="field5" onblur="calculate()" /><input type="text" name="total" id="total" /><script type="text/javascript">  function calculate() {	var field1 = document.getElementById('field1').value;	var field2 = document.getElementById('field2').value;	var field3 = document.getElementById('field3').value;	var field4 = document.getElementById('field4').value;	var field5 = document.getElementById('field5').value;	var total = document.getElementById('total');	//add your five fields together   //var sum = ...	//write out the total	total.value = sum;  }</script>

Link to comment
Share on other sites

Thanks for the help.Any guidance as to what would be a good reference for learning scripting? Most of the info I come across either is to basic or does not give real good examples of how to use in real world problems.Like the COD4 avatar.

Link to comment
Share on other sites

Thanks for the help.Any guidance as to what would be a good reference for learning scripting? Most of the info I come across either is to basic or does not give real good examples of how to use in real world problems.Like the COD4 avatar.
Quirksmode http://www.quirksmode.org/ is great for indepth tutorials but like was already mentioned, Google is great.Do you play COD4?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...