focus on a input field

L

leiko

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 ?
 
M

McKirahan

leiko said:
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>
 
L

leiko

What you have written works when you submit your form.

But I've tried with the 'OnBlur' event and that doesn't work.


<input name="Sectie" type="text" id="Sectie" size="4" maxlength="1" value
="<?php echo $Sectie; ?>"
onBlur="return OnlyCharacter(form1.Sectie.value)">

P.S. I use NN 7.1

How can I solve this problem ?
 
M

McKirahan

leiko said:
What you have written works when you submit your form.

But I've tried with the 'OnBlur' event and that doesn't work.


<input name="Sectie" type="text" id="Sectie" size="4" maxlength="1" value
="<?php echo $Sectie; ?>"
onBlur="return OnlyCharacter(form1.Sectie.value)">

P.S. I use NN 7.1

How can I solve this problem ?


I can't find a solution either.

Obviously, testing a field by "onblur=" or "onchange=" is problematic (on
NS).

I usually validate all fields at once via "onsubmit="...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top