onChange event and focus()

Discussion in 'Javascript' started by SimonFx, Feb 1, 2005.

  1. SimonFx

    SimonFx Guest

    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?

    <input type=text" name="tstfld" onChange="window.alert('Changed!');
    SimonFx, Feb 1, 2005
    1. Advertisements

  2. SimonFx

    SimonFx Guest

    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);


    <FORM NAME="myForm">
    <input type="text" name="myFld" onChange="validateField(this);">
    SimonFx, Feb 1, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.