Page 1 of 1
force search!
Posted: Mon Dec 30, 2002 4:34 am
by sirTemplar
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!
Posted: Mon Dec 30, 2002 7:13 am
by Johnm
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:
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>
You will obviously need to modify the code for your own use but that should get you started.
John M