Double or Square?

Value:
Double
Square
Result:


<SCRIPT>

function calculate(form, callingField) {
     if (callingField == "result") { // is the calling field the "result" field?
          // is the "square" radio button checked?
          if (form.action[1].checked) form.entry.value = Math.sqrt(form.result.value);
          else form.entry.value = form.result.value / 2;
     }
     else {
              if (form.action[1].checked) form.result.value = form.entry.value * form.entry.value;
              else form.result.value = form.entry.value * 2;
    }
}

</SCRIPT>

<FORM>
     Value:
     <INPUT TYPE="text" NAME="entry" VALUE="0"
    
  onChange="calculate(this.form, this.name);">
     Action:
    <INPUT TYPE="radio" NAME="action" VALUE="twice"
      onClick="calculate(this.form, this.name);">
    Double
    <INPUT TYPE="radio" NAME="action" VALUE="square"
      onClick="calculate(this.form, this.name);">
    Square Result:
     <INPUT TYPE="text" NAME="result" VALUE="0"
    
  onChange="calculate(this.form, this.name);">
</FORM>

calculate(this.form, this.name) passes 2 parameters:

this.form -- because we want to pass all the form's information to the function
this.name -- to tell the function what particular form element made the call