Search
 
SCRIPT & CODE EXAMPLE
 

HTML

how to set limit of words in input type text

<input type="text"title="likethis()"maxlength="200"placeholder="This will allow only 200 words">
Comment

js html input limit to 5 words

// Add event handler for event that can be cancelled and prevent excessive data
// from ever getting into the textbox
document.getElementById("input").addEventListener("keypress", function(evt){

  // Get value of textbox and split into array where there is one or more continous spaces
  var words = this.value.split(/s+/);
  var numWords = words.length;    // Get # of words in array
  var maxWords = 2;
  
  // If we are at the limit and the key pressed wasn't BACKSPACE or DELETE,
  // don't allow any more input
  if(numWords > maxWords){
    evt.preventDefault(); // Cancel event
  }
});
Comment

PREVIOUS NEXT
Code Example
Html :: internet and intranet 
Html :: placeholder in input field MVC 
Html :: click on toggle device toolbar page is not working 
Html :: emmet vscode twig 
Html :: browser favicon html 
Html :: input only accept numbers 
Html :: img text align 
Html :: how to comment in html 
Html :: align table in middle of page 
Html :: electron reload html 
Html :: disable close from screen modal popup 
Html :: how to add a image file in html 
Html :: fixed footer button css 
Html :: html table multiple headers 
Html :: input with plus and minus buttons 
Html :: how to emphasize text in html 
Html :: how to set logo on site tab 
Html :: meta redirect 
Html :: html boilerplate vscode 
Html :: how do i link two pages in html 
Html :: bootstrap buttons Disabled state 
Html :: how to put image in navbar 
Html :: add icon html 
Html :: cool css buton 
Html :: html arrow symbol 
Html :: how to add underline in markdown 
Html :: how to set table column width in html 
Html :: select required 
Html :: address tag in html 
Html :: how to insert input tag in html 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =