Jump to content

input length


verN

Recommended Posts

yes write a simple javascript function that checks the input field length and outputs an error or does nothing at all


<input id="name" type="text" name="name" onChange="checkInput()">

function checkInput()
{
var str = document.getElementById("name").value;
if ( str.Length > 20 )
{
alert("Please enter less than 20 characters");
}
}

Link to comment
Share on other sites

there is actually and even easier way to do it with out all the javascript

here is the code

<input id="name" type="text" name="name" maxlength="20">

its not complicated at all

and there can be no possibility that it will go over the limit

Link to comment
Share on other sites

Good idea rallokkcaz, that will work but wont throw the error requested

 

if its more then a error is outputted.

 

but both will work. one just prevents more than 20 the other one allows it but warns if you do, I suppose it comes down to information about the text box being available on the site to say that you are only allowed 20 characters etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.