Tuesday, April 23, 2013

Javascript focus()
Text field focus. focus().
Alternative code to focus()
Under IE, when an error occurs the cursor returns to the field with the error. Under Firefox, the cursor stays in the next (tabbed to) field. Is there a way to code this validation so that it would work for both??

Program:
<html>
<head>
<script language='javascript'>
function check()
{
    alert('hii');
    //document.joe.burns.focus(); This is valid for only internet explorer. And will not work on Firefox
    document.getElementById("
burns").focus();
    setTimeout("document.getElementById('burns').focus();",0);
}
function check2()
{
var letters2 = document.joe.tammy.value.length +1;
if (letters2 <= 4)
{document.joe.tammy.focus()}
else
{document.joe.chloe.focus()}
}

</script>
<body>
<FORM NAME="joe">
One:<INPUT TYPE="text" name="burns" id="burns" size="10" onchange="check()"><BR>
Two:<INPUT TYPE="text" name="tammy" size="10" onchange="check2()"><BR>
<INPUT TYPE="submit" VALUE="Click to Send" NAME="go">
</FORM>
</body>
</html>

0 comments:

Post a Comment