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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping focus on textbox if invalid?

Status
Not open for further replies.

MrPeds

Programmer
Jan 7, 2003
219
0
0
GB
Hi,

I have some code set up on a textbox to try and prevent the user from trying to enter data elsewhere if the textbox is invalid.

e.g.

<input type="text" id="i1" onchange="test(this)"></input>

..
test(ele)
{
if(ele.value=="" || ele.value ==null)
{
alert("error");
ele.focus();
}
}

The problem is, if i press the tab button, the textbox loses its focus. Basically, I want to force the user to correct their error before moving onto type into another text box or select something else on the webpage. Focus code does not always seem to be called.

How do i go about doing this?

Regards,

MrPeds
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top