<!-- Part of javalessons.com (c)2007 SEMM(NL) All rights reserved Author:P.Hamaker For educational purposes only.-->
<html>
<head>
<script type="text/javascript">
var n1, n2 ;
function tonumeric()
{
 var s1 ;
 s1 = document.getElementById('in1').value ;
 n1 = parseFloat( s1 ) ;
 if ( isNaN( n1 ) )
   throw 'A' ;
 s1 = document.getElementById('in2').value ;
 n2 = parseFloat( s1 ) ;
}
function clc( bt )
{
 try {
 tonumeric();
 var res ;
 switch ( bt.id )
 {
  case 'bt1' :
    res = Math.pow( n1, n2 ) ;  break;
  case 'bt2' :
    res = Math.sqrt( n1 ) ;  break;
  case 'bt3' :
    res = Math.max ( n1, n2 ) ;  break;
  case 'bt4' :
    res = n1 % n2 ;  break;
  case 'bt5' :
    res = n1 * ( Math.PI - n2 * n2 ) ;
    res += 11.1 ;
    res *= Math.round( 10 * Math.random() ) ;
 }
 document.getElementById('in3').value = res ;
 }
 catch ( exc )
 { document.getElementById('in3').value = 'Wrong input ' + exc ;  }
 document.getElementById('in1').focus() ;
}
</script>
</head>

<body style="font-family: sans-serif; font-size: large; margin-left: 20; margin-top: 30">
JavaScript Lesson Form, DOM and event handling
<form>A.
<input type="text" id="in1" maxlength="10" size="12">
B.<input type="text" id="in2" maxlength="10" size="12" value="0">
<input type="text" id="in3" size="22" readonly="readonly">
<p>
<input id="bt1" type="button" value="Power" onclick="clc(this)">
<input id="bt2" type="button" value="Squareroot" onclick="clc(this)">
<input id="bt3" type="button" value="Highest" onclick="clc(this)">
<input id="bt4" type="button" value="Remainder" onclick="clc(this)">
<input id="bt5" type="button" value="All kinds" onclick="clc(this)">
<input type="reset" value="Clear">
</form>
</body></html>