unable to set focus on textboxes using javascript -


i trying set focus on textboxes 1 1 on tab press not working me.

here code have tried:

function showstep2() {     document.getelementbyid('step2').style.visibility = 'visible'     document.getelementbyid('prevordquan').focus(); }  function showstep3() {     document.getelementbyid('step3').style.visibility = 'visible';     document.getelementbyid('takeoutamt').focus(); }      function showstep4() {     document.getelementbyid('step4').style.visibility = 'visible';     document.getelementbyid('compsperweek').focus(); } 

html:

<table style="width: 100%;" align="left">     <tbody>         <tr>             <td>how many takeout orders do each week?</td>             <td><input tabindex="1" type="text" name="prevordquan" id="prevordquan" size="6" value="7" onblur=" docalc1(); showstep2();"  /></td>         </tr>     </tbody> </table>  <table id="step2"  style="width: 100%;  visibility: hidden;"  align="left">     <tbody>         <tr>             <td>how many new takeout orders expect each week? (15% expected)</td>             <td><input tabindex="2" type="text" name="newordquan" id="newordquan" size="6" value="7" onblur="docalc(); showstep3();" /></td>         </tr>     </tbody> </table>  <table id="step3" style="width: 100%; visibility: hidden;" align="left">     <tbody>         <tr>             <td>how average takeout order?</td>             <td><input tabindex="3" type="text" name="takeoutamt" id="takeoutamt" size="6" value="20" onblur="docalc2(); showstep4();" /></td>         </tr>     </tbody> </table> 

there 3 textboxes,for 1st textbox have set focus on load this:

 function setfocus() {     document.getelementbyid("prevordquan").focus(); } 

it sets focus 1st textbox.after pressing tab on 1st textbox displays 2nd textbox focus not set on second textbox.

this problem need resolve.

you have problem in showstep2 function, focussing element id prevordquan first text box. think wanted focus newordquan.

so change

document.getelementbyid('prevordquan').focus(); 

to

document.getelementbyid('newordquan').focus(); 

and should work.

edit

you need focusable below text boxes (an additional input etc). otherwise if press tab on first (and only) textbox, browser focusses address bar , firing onblur event on both next textboxes , displaying both @ same time. here example of mean: http://jsfiddle.net/24tk4/1/

2nd edit

i think elegant solution of problem: http://jsfiddle.net/24tk4/2/

look @ link @ , of html code, displays invisible link.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -