onChange event and focus()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SimonFx

    onChange event and focus()

    Am I right in assuming that you can NOT set focus() back to a field in
    its onChange event? Is there another way - I have validation that I
    would like to set the focus back to the invalid field onChange?

    Eg:
    <input type=text" name="tstfld" onChange="windo w.alert('Change d!');
    this.focus()">
  • SimonFx

    #2
    Re: onChange event and focus()

    SimonFx wrote:[color=blue]
    > Am I right in assuming that you can NOT set focus() back to a field in
    > its onChange event? Is there another way - I have validation that I
    > would like to set the focus back to the invalid field onChange?
    >
    > Eg:
    > <input type=text" name="tstfld" onChange="windo w.alert('Change d!');
    > this.focus()">[/color]

    I think I have solved this using setTimeout, but it feels dirty.

    function validateField (f){
    // blah blah field is bad so:
    setTimeout ('document.' + f.form.name + '.' + f.name + '.focus()',100) ;
    setTimeout ('window.alert (\'Invalid entry.\')', 100);
    }

    </SCRIPT>
    </HEAD>
    <BODY>

    <FORM NAME="myForm">
    <input type="text" name="myFld" onChange="valid ateField(this); ">
    </FORM>

    Comment

    Working...