Click to See Complete Forum and Search --> : check input prior to search


philerimos
10-15-2003, 09:02 AM
Hello,

Would appreciate a little tip to get this simple function to work.

The function noblanks() prevents a search to be processed with an empty input. It works fine except for the fact that
I have to click twice on the Search button to get it to behave as expected. I just need to know what to put in place of
document.search.action = "results.php" to get the search request to work normally.

Here is the function:

<script language="JavaScript" type="text/JavaScript">
function noblanks() {
document.searchPhrase=document.search.phrase.value.toString().toLowerCase();
if(document.searchPhrase.length != 0) {
document.search.action = "results.php";
} else {
alert("An input is needed to perform your search");
}
}
</script>

Here is the button that triggers the Search:

<form name="search" action="JavaScript:noblanks();" method="get">
<td><input type="text" size="25" name="phrase" value="" maxlength="40"></td>
<td><input name="Search" type="Submit" value="Search"></td>
</form>

Thanks in advance.

pyro
10-15-2003, 09:06 AM
You might find it easier/better to use one of these:

http://www.infinitypages.com/research/formvalidation.htm
http://www.infinitypages.com/research/formvalidation_2.htm