Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > focus on a input field

Reply
Thread Tools

focus on a input field

 
 
leiko
Guest
Posts: n/a
 
      02-25-2004

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 ?


 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      02-25-2004
"leiko" <> wrote in message
news:4g6%b.13230$...
>
> 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>



 
Reply With Quote
 
 
 
 
leiko
Guest
Posts: n/a
 
      02-26-2004
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 ?




"leiko" <> schreef in bericht
news:4g6%b.13230$...
>
> 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 ?
>
>



 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      02-26-2004
"leiko" <> wrote in message
news:dag%b.13692$...
> 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="...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Input field focus after postback - v1.1 Adrian Parker ASP .Net 1 03-10-2006 01:23 PM
form input field, scroll bar and focus question... Indu Javascript 0 12-21-2005 02:43 PM
how can i catch a lost focus event from an input field inside a form =?ISO-8859-15?Q?Josef_Bl=F6sl?= HTML 1 07-20-2005 10:54 AM
How to focus the cursor in an input field when accessing a site Rune Runnestø Javascript 4 05-08-2005 11:50 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57