0

Enter key to move between form fields with submit button. I tried this code but its not working. This code is to move between form fields using enter key: Its working without submit button what changes should i do friends Please help me

<Script Language=JavaScript>

function toEOT(isField){

isRange = isField.createTextRange();
isRange.move('textedit');
isRange.select();
}

function actTab(isField){

if (event.keyCode == 13)
{
nextField = isField.tabIndex;
nextField++;
if (nextField < document.forms.Form1.length)
{document.forms.Form1[nextField].focus()}
else {document.forms.Form1[0].focus()}
}
}

function init(){

document.forms.Form1[0].focus();
}
event.preventDefault();
window.onload=init;

</Script><br>

</Head>
<Body>
<Form name='Form1'>
<fieldset>
<legend>Fills</legend>
<input type=text value="This is Some Text" size=25 onFocus="toEOT(this)" onKeyUp="actTab(this)" tabindex='1'><br>
<input type=text value="Some Text" size=25 onFocus="toEOT(this)" onKeyUp="actTab(this)" tabindex='2'><br>
<input type=text value="Nothing" size=25 onFocus="toEOT(this)" onKeyUp="actTab(this)" tabindex='3'><br>
<input type=text value="Two Words" size=25 onFocus="toEOT(this)" onKeyUp="actTab(this)" tabindex='4'><br>
<select >
<option>geetha</option>
<option>geetha</option>
<option>geetha</option>
</select>
<select >
<option>geetha</option>
<option>geetha</option>
<option>geetha</option>
</select>
<input type=text value="Two Words" size=25 /><br>
 <input style="margin:20px 20px 20px 250px;" type="submit" name="Submit" value="Submit"/>
</fieldset>
</Form>
  • 1
    To move between field you should not try to use `enter` key. because its default behavior is to submit the form. So just use TAB sequence for each field. – Parixit Jan 29 '14 at 05:10
  • Your code would need to pass the event and test it in all other browsers than ie – mplungjan Jan 29 '14 at 05:13
  • @mplungjan this code is working without submit button. its not working with submit button what changes should i do – user2978559 Jan 29 '14 at 05:16
  • possible duplicate of [Enter key press behaves like a Tab in Javascript](http://stackoverflow.com/questions/1009808/enter-key-press-behaves-like-a-tab-in-javascript) – mplungjan Jan 29 '14 at 05:29

1 Answers1

1

Add onclick="return false;" in the input tag for submit button ,then enter wil lead you to the next control.

<input style="margin:20px 20px 20px 250px;" type="submit" name="Submit" onclick="return false;" value="Submit"/>
Learner
  • 800
  • 1
  • 12
  • 34