How to prevent Mozilla using a link if a wrong number is in an input box

Discussion in 'HTML' started by Stefan Mueller, Feb 2, 2006.

  1. In my example the focus should only jump to textbox2 if you press the tab
    key and if '11' is in textbox1. That works fine.
    However if you enter e.g. '12' in textbox1 and click on 'Link', Mozilla
    shows the alert 'Wrong numer' but also jumps to 'www.google.com'.
    Opera and IE don't do that what's in my opinion the correct behavior.

    <html>
    <body>
    <script type = 'text/javascript'>
    function test(object) {
    if (object.value == 11) {
    return (true);
    }
    else {
    alert("Wrong number");
    return (false);
    }
    }
    </script>
    <form name = "my_form" action = "" method = "post" accept-charset =
    "iso-8859-1">
    <table id = "my_table" border = "1">
    <tr>
    <td>
    <input type = "text" name = "my_textbox1" onBlur = 'if
    (!test(document.my_form.my_textbox1))
    {setTimeout("document.my_form.my_textbox1.focus();", 1);}'>
    <input type = "text" name = "my_textbox2">
    <a href="http://www.google.com">Link</a>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    How can I prevent Mozilla from jumping to 'www.google.com' if the value in
    the input box is wrong?
    Stefan
     
    Stefan Mueller, Feb 2, 2006
    #1
    1. Advertising

  2. Stefan Mueller

    Chris Beall Guest

    Re: How to prevent Mozilla using a link if a wrong number is in aninput box

    Stefan Mueller wrote:
    > In my example the focus should only jump to textbox2 if you press the tab
    > key and if '11' is in textbox1. That works fine.
    > However if you enter e.g. '12' in textbox1 and click on 'Link', Mozilla
    > shows the alert 'Wrong numer' but also jumps to 'www.google.com'.
    > Opera and IE don't do that what's in my opinion the correct behavior.
    >
    > <html>
    > <body>
    > <script type = 'text/javascript'>
    > function test(object) {
    > if (object.value == 11) {
    > return (true);
    > }
    > else {
    > alert("Wrong number");
    > return (false);
    > }
    > }
    > </script>
    > <form name = "my_form" action = "" method = "post" accept-charset =
    > "iso-8859-1">
    > <table id = "my_table" border = "1">
    > <tr>
    > <td>
    > <input type = "text" name = "my_textbox1" onBlur = 'if
    > (!test(document.my_form.my_textbox1))
    > {setTimeout("document.my_form.my_textbox1.focus();", 1);}'>
    > <input type = "text" name = "my_textbox2">
    > <a href="http://www.google.com">Link</a>
    > </td>
    > </tr>
    > </table>
    > </form>
    > </body>
    > </html>
    >
    > How can I prevent Mozilla from jumping to 'www.google.com' if the value in
    > the input box is wrong?
    > Stefan
    >
    >


    Stefan,

    Ideally, here's what the user should see:

    - Textbox1, available for input.
    - Textbox2, available for input.
    - Link, disabled (perhaps presented in gray or otherwise subdued) and
    not in the tabbing order.

    When the user puts the cursor in textbox1, the background remains or
    becomes neutral, i.e. the same as when the page was initially displayed.
    When the user removes the cursor from textbox1, if the box contains
    '11', the background remains neutral; otherwise the background becomes
    red (to indicate an error). Tabbing to textbox2 is NOT inhibited.
    Optionally, a message appears, "field must contain 11".

    When the user puts the cursor in textbox2, the background remains or
    becomes neutral, i.e. the same as when the page was initially displayed.
    When the user removes the cursor from textbox2, if the box contains a
    valid value (you didn't specify what criteria are involved), the
    background remains neutral; otherwise the background becomes red (to
    indicate an error). Tabbing to textbox1 is NOT inhibited. Optionally,
    a message appears, "field must not be blank" (or whatever is appropriate).

    At any time that textbox1 contains '11' and textbox2 contains a valid
    value, the link is enabled and added to the tabbing sequence following
    textbox2.

    I assume your actual situation is a bit more complex, since it makes no
    sense to have a textbox which will only accept a single value.

    The above requires that you be able to check the field value each time a
    change is made, even if the cursor stays within that field. Look at the
    onkeypress or onkeyup attributes as a way to drive your validity checking.

    And not everyone has JavaScript enabled...

    Chris Beall

    P.S. I see no reason to criticize Mozilla's behavior here.
     
    Chris Beall, Feb 2, 2006
    #2
    1. Advertising

  3. I reprogrammed my whole web page with your great hints.
    I never thought about doing it like you told me. But it's of course the much
    better approach.

    Many thanks
    Stefan
     
    Stefan Mueller, Feb 21, 2006
    #3
  4. Stefan Mueller

    Jim Moe Guest

    Re: How to prevent Mozilla using a link if a wrong number is in aninput box

    Stefan Mueller wrote:
    > I reprogrammed my whole web page with your great hints.
    > I never thought about doing it like you told me. But it's of course the much
    > better approach.
    >
    > Many thanks
    >

    <blush>. Shucks, 'tweren't nothing'. You are so welcome.
    Umm. What are you talking about?

    --
    jmm (hyphen) list (at) sohnen-moe (dot) com
    (Remove .AXSPAMGN for email)
     
    Jim Moe, Feb 21, 2006
    #4
  5. > <blush>. Shucks, 'tweren't nothing'. You are so welcome.
    > Umm. What are you talking about?


    Not to treat Enter directly but instead to color the textbox e.g. red if the
    entry is invalid.

    Stefan
     
    Stefan Mueller, Feb 22, 2006
    #5
    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. ashutosh
    Replies:
    3
    Views:
    9,002
    Andrew Thompson
    Jun 16, 2005
  2. Gnarlodious
    Replies:
    4
    Views:
    17,611
    elizas
    May 5, 2010
  3. cjl
    Replies:
    1
    Views:
    10,503
    Michael Winter
    Oct 31, 2005
  4. cjl
    Replies:
    7
    Views:
    182
    Thomas 'PointedEars' Lahn
    Oct 30, 2005
  5. Stefan Mueller
    Replies:
    2
    Views:
    82
    Stefan Mueller
    Feb 1, 2006
Loading...

Share This Page