Hi,
I am working with a .net gridview and with many radnumerictextboxes inside the grid.
I have to move the focus to the next row, instead of next column (which is by default), on tab press in textbox. So for that I have fired onkeypress event of textbox, and if keychar is tab then, it will focus on the textbox below instead of beside box.
Here is a client side code and the onkeypress event. This code works well in Mozilla.
<asp:TemplateField HeaderText="Par" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="29px" |
ItemStyle-Width="29px" > |
<ItemTemplate> |
<telerik:radnumerictextbox runat="server" id="txtSinglePar" width="25px" onfocus="HasFocus(this)" |
emptymessage="Par"> |
<ClientEvents OnKeyPress="MoveToNextTextBox" /> |
<NumberFormat DecimalDigits="0" GroupSeparator="" /> </telerik:radnumerictextbox> |
</ItemTemplate> |
</asp:TemplateField> |
HasFocus() works well.
function HasFocus(TextBox) { |
textBoxWithFocus = TextBox; |
} |
And this is JS function of focusing on the next control, according to required logic.
function MoveToNextTextBox(sender, args) |
{ |
//IF TAB KEY HAS BEEN PRESSED |
if (args.get_keyCode() == 9) |
{ |
var str = textBoxWithFocus.id.replace("_text", ""); |
var id = str.substring(str.indexOf("_ctl"), str.indexOf("_txt")); |
//GET THE NUMBER OF THE ROW IN GRIDVIEW |
idid = id.replace("_ctl", ""); |
newId = parseFloat(id) + parseFloat(01); |
if (parseInt(newId) < 9) { |
newId = "0" + newId; |
} |
var prevID = str.replace(id, newId); |
if (parseFloat(id) < 9) |
{ |
prevIDprevID = prevID.replace("_ctl", "_ctl0"); |
prevIDprevID = prevID.replace("_ctl00", "_ctl0"); |
} |
var newCtl = document.getElementById(prevID); |
if (newCtl != null && $find(newCtl.id) != null) |
{ |
$find(newCtl.id).focus(); |
} |
args.set_cancel(true); |
} |
} |
While in Mozilla, it moves to the control in next row, in safari it does not. What is the reason?