...

View Full Version : Javascript ignoring HTML maxlength



Phalanxer
06-28-2012, 12:28 PM
I am using the following code which inserts the number '1' into a HTML INPUT field when toggled.

The INPUT field has a maxlength set to 2, yet if I toggle the JavaScript insert function three times, it ignores the fact that that there is already two characters in the INPUT field and inserts a third character.

Does anyone know if its possible for JavaScript to stop this?

I don't think there is, and so have just thought up a solution now.

Within the subroutine that inserts the number '1', I am going to use an if string to detect if there are two characters in the INPUT field, and if there are, then disable the function that I insert the number '1' with.

Does anyone know how I can make JavaScript detect if there are two characters in an INPUT field?

Phalanxer
06-28-2012, 12:35 PM
Well, it seems Nokia Browser recognizes the maxlength, where as Firefox does not.. so this is no longer an issue. Plus, what I asked wouldn't be feasble anyway, because 12 (1 and 2) and 2425 (24 and 25) are both two different numbers, but different character lengths.

sunfighter
06-28-2012, 03:23 PM
Hard to answer anything without code. And doesn't 'Nokia Browser' mean this is a question about phones?

felgall
06-29-2012, 12:15 AM
Whether the browser supports the maxlength attribute or not you can seill read the value tha attribute has from within JavaScript and take the appropriate action in the script.

Phalanxer
06-29-2012, 07:40 AM
Hard to answer anything without code. And doesn't 'Nokia Browser' mean this is a question about phones?

It doesn't matter what platform a web browser is running on. A webpage is a webpage and HTML is HTML.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum