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?

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...
}

~G

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; 
}
}

~G

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.