How to skip fields using javascript?

Question!

I have a form like this:

<form name="mine">
    <input type=text name=one>
    <input type=text name=two>
    <input type=text name=three>
</form>

When user types a value in 'one', I sometimes want to skip the field 'two', depending on what he typed. For example, if user types '123' and uses Tab to move to next field, I want to skip it and go to field three.

I tried to use OnBlur and OnEnter, without success.

Try 1:

<form name="mine">
    <input type=text name=one onBlur="if (document.mine.one.value='123') document.three.focus();>
    <input type=text name=two>
    <input type=text name=three>
</form>

Try 2:

<form name="mine">
    <input type=text name=one>
    <input type=text name=two onEnter="if (document.mine.one.value='123') document.three.focus();>
    <input type=text name=three>
</form>

but none of these works. Looks like the browser doesn't allow you to mess with focus while the focus is changing.

BTW, all this tried with Firefox on Linux.



Answers

Try to attach tabindex attribute to your elements and then programmaticaly (in javaScript change it):

<INPUT tabindex="3" type="submit" name="mySubmit">


Try onkeypress instead of onblur. Also, on the onfocus of field two is where you should be sending to three. I'm assuming you don't want them typing in two if one is 123 so you can just check that on two's onfocus and send on to three.

By : Chuck


<form name="mine">
    <input type="text" name="one" onkeypress="if (mine.one.value == '123') mine.three.focus();" />
    <input type="text" name="two">
    <input type="text" name="three">
</form>


This video can help you solving your question :)
By: admin