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

textbox change when it get focus - validation

Status
Not open for further replies.

nomu26

Programmer
Sep 10, 2003
22
ZA
I have a problem formatting the textbox, like changing the color and inserting a cursor on the field with an error when I'm validating the form field.
Can someone give me a script on how to do this and how do I call the javascript in the form tag cause if I call it in the button it doesn' work since the button runs on the server.
I'm desperate guys.
Nomvula
 
You can use onBlur for the event like this:

<html>
<head>
<title>Textbox</title>
<script language=&quot;JavaScript&quot;>
function chk_val() {
d = document.test;
if(d.vala.value.length > 0 && d.vala.value !=&quot;Please Enter Data..&quot;)
{ alert(&quot;OK&quot;); }
else {
alert(&quot;Need More Info in Box A&quot;);
d.vala.value = &quot;Please Enter Data..&quot;;
d.vala.focus();
d.vala.select();}
}
</script>
</head>
<body><form name=&quot;test&quot;>
Box A:<br>
<input type=&quot;text&quot; name=&quot;vala&quot; size=&quot;20&quot; onBlur=&quot;chk_val()&quot;>
</form>
</body>
</html>

2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top