Javascript Form How to - TextField requests focus








Question

We would like to know how to textField requests focus.

Answer


 <!--from   w ww  . ja  v a 2 s. co m-->
<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">
    Enter first number:<input name="FirstInput" type="text">
    Enter second number:<input name="SecondInput" type="text">
    Enter 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: