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 Link to comment https://forums.phpfreaks.com/topic/46685-input-length/ 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"); } } Link to comment https://forums.phpfreaks.com/topic/46685-input-length/#findComment-227445 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 Link to comment https://forums.phpfreaks.com/topic/46685-input-length/#findComment-228581 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. Link to comment https://forums.phpfreaks.com/topic/46685-input-length/#findComment-228615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.