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

Keyboard Events in JavaScript

Status
Not open for further replies.

ajayg

Programmer
Oct 24, 2000
7
US
I have a problem: I have a textbox. I have to do validations on that text box using keyPress/Down events. How should I go about it?
Validation: I don't want to allow the user to enter any value other than "zero" 0.

thank you in Advance

Ajay
 
so why dod you want user to enter that zero? set it as a default value..

but anyway, here is an example:
<html><head><title>validating</title>
<script>
function validate(value,flag){
if (value.length!=0){
if (parseFloat(value)!=0){
alert('wrong');
if (flag) return false
}else if (flag) return true
}else if (flag){alert('enter zero'); return false}
}
</script>
</head>
<body>
<form onsubmit=&quot;return validate(this.txt1.value,true)&quot;>
<input type=&quot;text&quot; name=&quot;txt1&quot; onblur=&quot;validate(this.value,false)&quot;>
<input type=&quot;submit&quot; name=&quot;sub1&quot; value=&quot;just do it&quot;>
</form>
</body>
</html>
Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top