I am new to javascript and am currently learning it with the book Wrox Beginning Javascript 3rd ed.
I have just encountered a problem that I am not able to figure out. Could you please help me out.....
The problem is that select() and focus() are not working in FF2.0 but works in IE7.
This is what the code is supposed to do:
1. I enter a age
2. If I enter non numerical data and then I tab out of the text area
3. An alert box pops up and tells me to correct the age.
4. On hitting ok it goes back to the age field.
But in FF its going to the next tag(the submit button).
This is the code:
CODE
<script type="text/javascript">
function txt_age_onblur()
{
var in_txt_age = document.form1.txt_age;
if (isNaN(in_txt_age.value))
{
alert("Please enter a valid age");
in_txt_age.focus(); //looks as if no need for focus() as I am able to edit the text with only select() in IE. Not working with FF.
in_txt_age.select(); //Not working with FF
}
}
</script>
</head>
<body>
<form name=form1>
Age:
<input type=text name=txt_age onblur="txt_age_onblur()" size=3 maxlength=3 />
<input type=button value=Submit />
</form>
</body>
</html>
function txt_age_onblur()
{
var in_txt_age = document.form1.txt_age;
if (isNaN(in_txt_age.value))
{
alert("Please enter a valid age");
in_txt_age.focus(); //looks as if no need for focus() as I am able to edit the text with only select() in IE. Not working with FF.
in_txt_age.select(); //Not working with FF
}
}
</script>
</head>
<body>
<form name=form1>
Age:
<input type=text name=txt_age onblur="txt_age_onblur()" size=3 maxlength=3 />
<input type=button value=Submit />
</form>
</body>
</html>
Thanks for you time friends. Smile..............

