Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return focus to field when validation fails.If the

Status
Not open for further replies.

Jacqui1811

Programmer
Jul 8, 2002
100
SG
Hy guys.
I have a few textboxes that need to be numerical.
The on blur event fires an isNumerical javascript function.
If the value is not numerical I show an alert box stating that the value needs to be numerical. Problem is that I want to return focus to that field and at the moment it just moves on to the next one.
Hope you can help. Code is below :

Here is the function.
<script language="javascript" type="text/javascript">
function isNumeric(textBox, boxName)
{
if(isNaN(textBox.value))
{
alert("The input needs to be numerical for field " + boxName);
textBox.focus();
return false();
}
}
</script>

Here is the calling code.
<asp:textbox id="txtNoEpisodes" size="2" maxlength="3" runat="server" onblur="isNumeric(this, 'txtNoEpisodes')"></asp:textbox>

Thanks in advance.
Jacqui
 
just do this:

Code:
onblur="return isNumeric(this);"

you don't need to pass in the textbox's name, you can access it in the function in this manner:

Code:
alert("The input needs to be numerical for field " + textBox.name);

and don't forget to change your function declaration to this:

Code:
function isNumeric(textBox)

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
Thanks for the tip.
However I have tried it but the focus still goes to the next text box !!!.
Jacqui.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top