JavaScript Forms

By Herbert J. Bernstein
© Copyright 2004 Herbert J. Bernstein

Managing Forms with JavaScript

Web pages can use JavaScript to manage forms, either to check and filter input before sending it to a cgi-bin script to perform the form actions on a server, or by doing the processing completely on the client side.

Temperature °F:
Temperature °K:



<form name="my_form">
Temperature &deg;F: 
<input type="text" name="tempF" size=30 value="68"
 onChange="xtempF = parseFloat(document.my_form.tempF.value);
           xtempK = ((xtempF - 32)*5)/9 + 273.15; //convert to degrees Kelvin
           xtempK = (Math.round(xtempK*100))/100; //round to the nearest 1/100th
           document.my_form.tempK.value = xtempK;"></input>
<br>
Temperature &deg;K:
<input type="text" name="tempK" size=30 value="  "
 onChange="xtempK = parseFloat(document.my_form.tempK.value);
           xtempF = ((xtempK - 273.15)*9)/5 + 32; //convert to degrees F
           xtempF = (Math.round(xtempF*100))/100; //round to the nearest 1/100th
           document.my_form.tempF.value = xtempF;"></input>
</form>
<P>



Prepared by Herbert J. Bernstein 27 October 2004.

© 2004 Herbert J. Bernstein. All Rights Reserved.