Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Banned
    Join Date
    Jun 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Banned
    Join Date
    Jun 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,092
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Hard to answer anything without code. And doesn't 'Nokia Browser' mean this is a question about phones?

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Banned
    Join Date
    Jun 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •