verN Posted April 12, 2007 Share Posted April 12, 2007 how would i in javascript check that the user has entered characters less then for instance 20 if its more then a error is outputted. <input type=text name=name> could i use onchnage to do this thnaks Quote Link to comment Share on other sites More sharing options...
paul2463 Posted April 12, 2007 Share Posted April 12, 2007 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"); } } Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted April 13, 2007 Share Posted April 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
paul2463 Posted April 13, 2007 Share Posted April 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.