focus on a input field

Discussion in 'Javascript' started by leiko, Feb 25, 2004.

  1. leiko

    leiko Guest

    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 ?
     
    leiko, Feb 25, 2004
    #1
    1. Advertising

  2. leiko

    McKirahan Guest

    "leiko" <> wrote in message
    news:4g6%b.13230$-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>
     
    McKirahan, Feb 25, 2004
    #2
    1. Advertising

  3. leiko

    leiko Guest

    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$-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 ?
    >
    >
     
    leiko, Feb 26, 2004
    #3
  4. leiko

    McKirahan Guest

    "leiko" <> wrote in message
    news:dag%b.13692$-ops.be...
    > 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="...
     
    McKirahan, Feb 26, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adrian Parker

    Input field focus after postback - v1.1

    Adrian Parker, Mar 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    481
    Steven Cheng[MSFT]
    Mar 10, 2006
  2. =?ISO-8859-15?Q?Josef_Bl=F6sl?=
    Replies:
    1
    Views:
    25,964
  3. Rune Runnestø
    Replies:
    4
    Views:
    190
    Thomas 'PointedEars' Lahn
    May 8, 2005
  4. Indu
    Replies:
    0
    Views:
    168
  5. Roger
    Replies:
    3
    Views:
    351
Loading...

Share This Page