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

onkeydown / onchange event of a textarea 1

Status
Not open for further replies.

bitwise

Programmer
Mar 15, 2001
269
US
How can I restrict the use of the 'Enter' key in an onkeydown() or an onchange() event of a &lttextarea> element?

Thanks,
bitwise
 
If you mean disallow by restrict then you can watch for the enter keystroke like this:

Sub textArea_onkeyup
If window.event.keycode = 13 Then
textArea.value = Left(textArea.value, Len(textArea.value - 1))
End If
End Sub

I think that should work, sorry if it doesn't. Hope I've helped... "A computer scientist is a person who knows when it is time to hit the computer."

John

johnmc@mvmills.com
 
Logically that makes sense but it doesn't quite work. Isn't there a way to just return false or cancel the event when 'window.event.keycode = 13'?

bitwise
 
Try this:

Sub textArea_onkeydown
If window.event.keycode = 13 Then
window.event.returnvalue = false
End If
End Sub

that should cancel the event but I don't know if it will cancel the enter from being put in.
Hope THIS works!:) "A computer scientist is a person who knows when it is time to hit the computer."

John

johnmc@mvmills.com
 
Thanks, that was what I was looking for.

bitwise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top