Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check input value length

I have a problem with input checking. I don't want to send the request if the input length is less than 3.

My form:

<form method='post' action=''>     Albūma nosaukums: # # this is the input --><input id='titleeee' type='text' name'album_title' /><br />      Bilde Nr 1: <input type='file' name='pic_nr1' /><br />     Bilde Nr 2: <input type='file' name='pic_nr2' /><br />     Bilde Nr 3: <input type='file' name='pic_nr2' /><br />      Aktīvs*:      <select>         <option>Jā</option>         <option>Nē</option>     </select>      <br />      <input Onclick='testlenght(document.getElementById("titleeee"), "Tavs albūma nosaukums ir pa īsu!", "3")' type='submit' value='Pievienot' /> </form> 
like image 367
user1609394 Avatar asked Aug 28 '12 17:08

user1609394


People also ask

How do you find the length of an input?

In this tutorial, we are going to learn about how to get the length of an entered text in textbox using JavaScript and jQuery. To get the length of an input textbox, first we need to use access it inside the JavaScript by using the document. getElementById() method. const textbox = document.

How do you change input value length in HTML?

Input value length You can specify a minimum length (in characters) for the entered value using the minlength attribute; similarly, use maxlength to set the maximum length of the entered value, in characters. The example below requires that the entered value be 4–8 characters in length.


1 Answers

You can add a form onsubmit handler, something like:

<form onsubmit="return validate();">  </form>   <script>function validate() {  // check if input is bigger than 3  var value = document.getElementById('titleeee').value;  if (value.length < 3) {    return false; // keep form from submitting  }   // else form is good let it submit, of course you will   // probably want to alert the user WHAT went wrong.   return true; }</script> 
like image 186
dm03514 Avatar answered Oct 04 '22 02:10

dm03514