Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  189] [ 2]  / answers: 1 / hits: 49238  / 13 Years ago, sat, december 17, 2011, 12:00:00

I want to change keycode in keydown ( key press ) in all input in a page.I want to replace Enter keycode with TAB key code. How I can do this?



thanks






EDIT 1)



Consider this code:



<div>
<asp:RadioButtonList ID=RadioButtonList1 runat=server>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
<asp:TextBox ID=TextBox1 runat=server>3333</asp:TextBox>
<br />
<br />
<asp:DropDownList ID=DropDownList1 runat=server>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
</div>


I want when user press Enter on eny of above control focus go to next control.



thanks


More From » jquery

 Answers
38

I think this work:



 $('input').live(keypress, function (e) {
/* ENTER PRESSED*/
var OffSet = 0;
if (e.keyCode == 13) {
/* FOCUS ELEMENT */
if ($(this).is(input[type='radio'])) {
var tblID = $(this).closest('table').attr('id');
var radios = $('#' + tblID).find(:input);
//alert(radios.index(this));
OffSet = radios.length - radios.index(this) - 1;
}
//alert(OffSet);

var inputs = $(this).parents(form).eq(0).find(:input);
var idx = inputs.index(this);
inputs[idx + OffSet].blur();

try {
inputs[idx + OffSet].selectionStart = inputs[idx + OffSet].selectionEnd = -1;
} catch (e) {

}
if (idx == inputs.length - 1) {
inputs[0].select();
} else {
inputs[idx + 1 + OffSet].focus(); // handles submit buttons
try {
inputs[idx + 1 + OffSet].select();
} catch (e) {
}
}
return false;
}
});

[#88511] Thursday, December 15, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marisela

Total Points: 103
Total Questions: 105
Total Answers: 102

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
;