force search!
Moderator: General Moderators
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
force search!
i have a form to search my database. what do i have to put to force those who search to fill-in at least one search field? because right now, when someone clicks on seach without anything, it will bring out all the data on the database
, please help!
- Johnm
- Forum Contributor
- Posts: 344
- Joined: Mon May 13, 2002 12:05 pm
- Location: Michigan, USA
- Contact:
I recommend using something like JavaScript to validate the input. Change the button type (in HTML) from submit to button where it call a function to validate the data in the form when the user clicks on it.
Example:
You will obviously need to modify the code for your own use but that should get you started.
John M
Example:
Code: Select all
<input type="button" value="Continue ->" onClick="validate_form(this.form)">
// Function to validate the input of the form
<script>
function validate_form(form)
{
if ( form.s_type.optionsїform.s_type.selectedIndex].text=="")
{
alert("You must select a unit type");
form.s_type.focus();
return false;
}
if ( form.s_base_type.optionsїform.s_base_type.selectedIndex].text=="")
{
alert("You must select a base type");
form.s_base_type.focus();
return false;
}
form.submit();
}
</script>John M