How do I prevent this.focus(); from going to the next table row??

Discussion in 'Javascript' started by tlyczko, Jan 17, 2006.

  1. tlyczko

    tlyczko Guest

    I have this code in a form input box contained in the 4th column cell
    of a 4-column table:

    onblur = "if (testExp(this.value, 'message') == false) {window.focus();
    this.focus();}"

    testExp checks the input box form value, but every time it is false
    (wrong kind of value), the focus goes to the form input box in the 1st
    column of the *next* table row.

    The "wrong" kind of value gets placed into the input box, then the
    cursor goes to the first column in the next table row.

    How do I prevent this?? Happens with either IE or FF, it only needs to
    work properly in IE though.

    Thank you,
    Tom
    tlyczko, Jan 17, 2006
    #1
    1. Advertising

  2. tlyczko

    Randy Webb Guest

    tlyczko said the following on 1/17/2006 1:33 PM:
    > I have this code in a form input box contained in the 4th column cell
    > of a 4-column table:
    >
    > onblur = "if (testExp(this.value, 'message') == false) {window.focus();
    > this.focus();}"


    have testExp set the focus.

    Don't use onblur, use onchange, to validate fields.

    function testExp(fieldRef,message){
    ...........

    fieldRef.focus();
    }

    If you don't set focus, then the next field in Tab Order will gain focus.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Jan 17, 2006
    #2
    1. Advertising

  3. tlyczko

    tlyczko Guest

    Thank you, Randy...

    I finally got it working after your suggestion, although the best I can
    do so far is to return the focus to where it belongs.

    Hopefully tonight I can figure out how to shade the text box if it has
    the wrong type data in it...

    Thank you, Tom
    tlyczko, Jan 17, 2006
    #3
  4. tlyczko

    RobG Guest

    tlyczko wrote:
    > Thank you, Randy...
    >
    > I finally got it working after your suggestion, although the best I can
    > do so far is to return the focus to where it belongs.
    >
    > Hopefully tonight I can figure out how to shade the text box if it has
    > the wrong type data in it...


    You can attempt that with CSS by modifying the input's style object
    where supported, but not all browsers will obey.


    --
    Rob
    RobG, Jan 18, 2006
    #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. phl
    Replies:
    1
    Views:
    4,345
    Martin Jay
    Jun 8, 2006
  2. douha
    Replies:
    1
    Views:
    312
    Toby Inkster
    Jan 4, 2007
  3. Deniz Bahar
    Replies:
    2
    Views:
    464
    Andrey Tarasevich
    Mar 9, 2005
  4. D
    Replies:
    0
    Views:
    205
  5. Roger
    Replies:
    3
    Views:
    322
Loading...

Share This Page