Jump to content

onkeypress for input field?


random1

Recommended Posts

I have a form field that I'm currently allowing only positive numbers to be entered in.

 

I'm currently using onkeypress on the input field:

 

<input name="card_security_code" type="text" maxlength="4" size="4" onkeypress="return onlyNumbers(event);" />

 

It's currently working although I'm concerned about using onkeypress, is it  reliable and does this fire when using things like ipod and mobile devices?

 

I've heard that using onblur is not recommended for this and I've tried using onchange but that does not work.

 

Any suggestions on what I should use for this kind of field validation?

Link to comment
https://forums.phpfreaks.com/topic/234936-onkeypress-for-input-field/
Share on other sites

not sure about mobile devices and ipods. Some of these have JS turned off by default. Do you have a fallback option for this case? I would personally use onBlur to check the value and then use a php script to check when the form is being submitted. That way people with JS turned off will still recieve an error when entering the wrong values.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.