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. Advertisements

  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. Advertisements

  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. Advertisements

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. Thomas Scheiderich

    autopostback not going to next field

    Thomas Scheiderich, Feb 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    381
    Thomas Scheiderich
    Feb 17, 2004
  2. Anon
    Replies:
    2
    Views:
    1,179
    Jukka K. Korpela
    Mar 18, 2005
  3. phl
    Replies:
    1
    Views:
    4,684
    Martin Jay
    Jun 8, 2006
  4. douha
    Replies:
    1
    Views:
    385
    Toby Inkster
    Jan 4, 2007
  5. Deniz Bahar
    Replies:
    2
    Views:
    712
    Andrey Tarasevich
    Mar 9, 2005
  6. D
    Replies:
    0
    Views:
    488
  7. Giggle Girl

    ie6 Insert Row at specific Row Index of Table

    Giggle Girl, Feb 5, 2006, in forum: Javascript
    Replies:
    18
    Views:
    562
    Thomas 'PointedEars' Lahn
    Feb 7, 2006
  8. Roger
    Replies:
    3
    Views:
    597
Loading...