Limit how many words can be entered into an input

Discussion in 'JavaScript' started by qwikad.com, Dec 9, 2020.

  1. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #21
    Like my initial post, you kind of missed what they're after. Unlike my initial post, what you've done is "JavaScript for nothing" since pattern="" can do the same thing.

    Also, what makes a label + input a grammatical <p>aragraph? Why are you using the onevent trash like it's still 1998? Why state empty values?

    And you REALLY need to read the whole thread, see how "onkeydown" doesn't work on some mobile device inputs. For space or other delimit methods you should be checking "oninput" instead... mind you, that's not entirely on you. "oninput" is a semi-recent (if 2005 to 2006 can be called "recent") addition to JavaScript that hasn't gotten enough word of mouth.

    Really for full "proper" behavior, one should be trapping onkeydown for "Enter" with an event.preventDefault(), oninput for " " (space), AND onblur.

    Things crapping the JavaScript events into the markup is going to hobble the implementation of.
     
    deathshadow, Dec 19, 2020 IP
    JEET likes this.
  2. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #22
    @deathshadow
    I agree "oninput" will be a better choice than "onkeydown".
    And I also agree, if it can be done without js, then that is the best choice!
     
    JEET, Dec 19, 2020 IP