Javascript Form How to - Set Form focus








Question

We would like to know how to set Form focus.

Answer


<!--from  w  ww.jav  a 2  s.  c om-->
<html>
<head>
<script type="text/javascript" language="javascript">
function SetFocus(){
    document.SimpleForm.FirstInput.focus();
}

function FindMaxAndMin(){
        SetFocus();
}
</script>
</head>
<body onload="SetFocus()">
    <form name="SimpleForm">
         First number:<input name="FirstInput" type="text">
         Second number:<input name="SecondInput" type="text">
         Third number:<input name="ThirdInput" type="text">
         <button type="Button" onclick="FindMaxAndMin()"> Click to calculate</button>
    </form>
</body>
</html>

The code above is rendered as follows: