Jump to content

form Validation


s_ff_da_b_ff

Recommended Posts

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 != "")
   .....
   }  
}

Link to comment
https://forums.phpfreaks.com/topic/174355-form-validation/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/174355-form-validation/#findComment-919177
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.