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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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