"Ike" schreef
Can anyone please point me to an example showing a textfield that only
allows a certain kind of character typed in? I need to create a text field
where only an opening or closing parentheses can be input ('(' or ')').
Seems to me that a textfield is not the best suited for this job, where
<select>
<option value="(">(</option>
<option value=")">)</option>
</select>
does the job without any script at all! Radiobuttons are great for this sort
of thing too.
Otheriwse, with 40 and 41 being the character codes for respectively the
opening or closing parentheses, the following code will return false and so
nullify the event for all other characters.
<input onkeypress="var k = event.keyCode || event.charCode || event.which;
return k===40 || k===41;">
hth
ivo
http://4umi.com/web/javascript/