1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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,635
    Likes Received:
    1,971
    Best Answers:
    249
    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.
    SEMrush
     
    deathshadow, Dec 19, 2020 IP
    JEET likes this.
    SEMrush
  2. JEET

    JEET Notable Member

    Messages:
    3,758
    Likes Received:
    493
    Best Answers:
    19
    Trophy Points:
    235
    #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