I have an HTML form that has fields that allows a database to be searched and the results displayed.

When initially displaying the page, all the records of the database appear, as if a search was performed without any query values.

Is there any javascript coding that will stop the results loading?

7 Years
Discussion Span
Last Post by Graphix

When a page loads, no form will be automatically submitted. You should check whether the PHP-script also performs a action if no values are submitted (if $_POST is empty) and stop it from doing if that is true:

if ($_POST['search_words'] != "") {
// ... Query the database etc...


PS: if you want a form to not be submitted you should write a javascript function that returns true if the query-field is not empty and false if not. You should call it like this:

<form onsubmit="return SearchFieldNotEmpty();" method="post">

and the function should be something like this:

function SearchFieldNotEmpty() {
if (document.getElementById("search_words").value == "") {
return false; 
} else { 
return true; 


Edited by Graphix: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.