"leiko" <dd***@pandora.be> wrote in message
news:4g********************@phobos.telenet-ops.be...
I've written the following function who works great in IE
function OnlyCharacter(tekst)
{
if (tekst.length == 1)
{
if (tekst >= "A" && tekst <="Z")
{return true}
}
window.alert ("Only uppercase");
form1.Sectie.focus();
}
But in Netscape or Mozilla I can't bring back the focus on the field
(Sectie) when the input is not correct
I've tried the following :
1) var box;
box = document.forms[0].elements[1];
box.focus()
2)document.getElementById("Sectie").focus();
3) document.form1.Sectie.focus()
but nothing seems to work.
How must I do that in Netscape and/or Mozilla ?
Below I added "document." in front of your "form1." references.
Also, I added the following lines:
document.form1.Sectie.select();
return false;
I tried the following and had no problem on NS 6.2.2:
<html>
<head>
<title>AZ.htm</title>
<script type="text/javascript">
function OnlyCharacter(tekst)
{
if (tekst.length == 1)
{
if (tekst >= "A" && tekst <="Z")
{return true}
}
window.alert ("Only uppercase");
document.form1.Sectie.focus();
document.form1.Sectie.select();
return false;
}
</script>
</head>
<body>
<form name="form1" onsubmit="return OnlyCharacter(form1.Sectie.value)">
<input type="text" size="1" maxlength="1" name="Sectie">
<input type="submit" value="Submit">
</form>
</body>
</html>