Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-28-2012, 11:28 AM   PM User | #1
Phalanxer
Banned

 
Join Date: Jun 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
Phalanxer can only hope to improve
Javascript ignoring HTML maxlength

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?

Last edited by Phalanxer; 06-28-2012 at 11:30 AM..
Phalanxer is offline   Reply With Quote
Old 06-28-2012, 11:35 AM   PM User | #2
Phalanxer
Banned

 
Join Date: Jun 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
Phalanxer can only hope to improve
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.

Last edited by Phalanxer; 06-28-2012 at 11:38 AM..
Phalanxer is offline   Reply With Quote
Old 06-28-2012, 02:23 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Hard to answer anything without code. And doesn't 'Nokia Browser' mean this is a question about phones?
sunfighter is offline   Reply With Quote
Old 06-28-2012, 11:15 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 06-29-2012, 06:40 AM   PM User | #5
Phalanxer
Banned

 
Join Date: Jun 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
Phalanxer can only hope to improve
Quote:
Originally Posted by sunfighter View Post
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.
Phalanxer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:43 AM.


Advertisement
Log in to turn off these ads.