I'm trying to set the focus and select the contents of a textbox on an aspx page if the javascript Custom Validation fails.. Ex:
<asp:textbox id="AccountNumber"></asp:textbox>
<asp:CustomValidator id="custValAccountNumber" Runat="server" ErrorMessage="Invalid Account Number" ControlToValidate="AccountNumber" Display="Dynamic" ClientValidationFunction="ValidateAccountNumber">*</asp:CustomValidator>
<script language=javascript>
function ValidateAccountNumber(oSrc, args)
{
if (args.Value != "123465"
{
window.alert("Invalid Account Number!"
;
document.getElementById('AccountNumber').focus();
document.getElementById('AccountNumber').select();
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
For some reason it doesn't seem like the focus or the select is working. The focus just goes to the next field in the tab index. Help please!
<asp:textbox id="AccountNumber"></asp:textbox>
<asp:CustomValidator id="custValAccountNumber" Runat="server" ErrorMessage="Invalid Account Number" ControlToValidate="AccountNumber" Display="Dynamic" ClientValidationFunction="ValidateAccountNumber">*</asp:CustomValidator>
<script language=javascript>
function ValidateAccountNumber(oSrc, args)
{
if (args.Value != "123465"
{
window.alert("Invalid Account Number!"
document.getElementById('AccountNumber').focus();
document.getElementById('AccountNumber').select();
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
For some reason it doesn't seem like the focus or the select is working. The focus just goes to the next field in the tab index. Help please!