s_ff_da_b_ff Posted September 15, 2009 Share Posted September 15, 2009 Ok so I need help with my form validation. There is a drop down menu with these options: First Name Last Name Email Next to the Drop down menu is an input box where the user types in either there first name, last name, email or a combination of both first and last name. Then the query is submited and is sent off to the DB where all the users with related names appear. Example: 1. *base case* user doesnt type in anything to the input box : error message appears 2. User does not select anything in the drop down but types in name: All people with same name should appear 3. I select first name in drop down menu I type in : 'Steve' into the input box and hit submit all people with first name Steve appear you get the picture heres what I have so far (no much) function searchValidation(){ valid = true; if (document.search_form.input.value == "") { alert ( "Please fill in search criteria" ); valid = false; } else { (document.search_form.input.value != "") ..... } } Quote Link to comment Share on other sites More sharing options...
syed Posted September 15, 2009 Share Posted September 15, 2009 Hope this helps <script language="javascript"> function doSearch(){ var filter = document.getElementById("filter").value; var search = document.getElementById("search").value; var submit = false; if ((filter) && !(search)){ alert("please enter a search criteria to filter by"); submit = false; }else if ((filter) && (search)){ alert(filter + "=" + search); submit = true; }else if (search){ alert("firstname=" + search); submit = true; }else{ alert("please enter a search criteria"); submit = false; } if (submit){ alert("All done submitting now"); document.form.submit(); } } </script> <form action="" method="post" name="form"> <select name="filter" id="filter"> <option value="">Select</option> <option value="firstname">First Name</option> <option value="lastname">Last Name</option> <option value="email">Email</option> </select> <input type="text" name="search" id="search" /> <input type="button" name="btnSearch" value="Search" onclick="doSearch()" /> </form> 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.