Real time updating of values on a form

Place an event handler on the onBlur event. If you had a Javascript function called calculateStuff(), your input element could reference it like this:

<input name="something" type="text" onblur="calculateStuff();" value="">

The onBlur event happens when the user leaves the field. If you want it to happen as they are still typing, you could use the onChange handler in the same way.


If you want to display 'realtime' (meaningly, as the user types) values, you can use the keyup values :

  • http://www.w3schools.com/jsref/event_onkeyup.asp (for pure javascript)
  • http://api.jquery.com/keyup/ (for jquery)

Yes. You should call an onkeyup / onchange event in JavaScript to determine if the user has typed anything and inside the event just have it call a JavaScript function which refreshes the form by doing the math and inserting the values.

You can also add other event listeners such as blur etc.

It has been a while so i cant post any usable code but Google is your friend here.