yandoo Posted June 7, 2007 Share Posted June 7, 2007 Hi, Im currently adding some validation to my search field. So far i have added validation that dislpays a mesage when the user leaves the search field empty. The following code is how i have done this: <script type="text/javascript"> function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") {alert(alerttxt);return false} else {return true} } } function validate_form(thisform) { with (thisform) { if (validate_required(finda,"Email must be filled out!")==false) {finda.focus();return false} } } </script> <form name="search" method="get" action="search_client_details.php" onsubmit="return validate_form(this)"> <input type="text" name="finda"/> <span class="style10">in</span> <Select NAME="field"> <Option VALUE="Client">Client Name</option> <Option VALUE="DepartmentCode">Department</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> I would like to make it so that the user can not only leave the search field empty but also the user MUST use at least 3 characters when searching. If the user was searching for a name in the database they would need to input the first three letters into the search field......... E.G. If they are searching for a record name called Thomas (they would as a minimum) need to enter the first 3 letters THO. Is this possible please????? If so how do i do it???? Any help is greatly appreciated Thanks Tom Quote Link to comment Share on other sites More sharing options...
taith Posted June 7, 2007 Share Posted June 7, 2007 that would be something for the javascript forum... not the php one ... grr... drat my perfect timing again! lol... Quote Link to comment Share on other sites More sharing options...
per1os Posted June 7, 2007 Share Posted June 7, 2007 Post in the correct forum, this is PHP not Javascript. Quote Link to comment Share on other sites More sharing options...
taith Posted June 7, 2007 Share Posted June 7, 2007 Post in the correct forum, this is PHP not Javascript. uuuh... javascript not php* Quote Link to comment Share on other sites More sharing options...
nogray Posted June 7, 2007 Share Posted June 7, 2007 Just change this line if (value==null||value=="") to if (value.length < 3) Quote Link to comment Share on other sites More sharing options...
per1os Posted June 8, 2007 Share Posted June 8, 2007 Post in the correct forum, this is PHP not Javascript. uuuh... javascript not php* Eh what I meant was this is the PHP Forum not the Javascript forum. EDIT: Just noticed it got moved, oh well. I will look like a jackass. Quote Link to comment Share on other sites More sharing options...
taith Posted June 9, 2007 Share Posted June 9, 2007 Post in the correct forum, this is PHP not Javascript. uuuh... javascript not php* Eh what I meant was this is the PHP Forum not the Javascript forum. EDIT: Just noticed it got moved, oh well. I will look like a jackass. lol... dont worry... i had impecable timing too 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.