I have the following form on my site. It's simple, one search input field and one submit button:
<form id="search-form" name="search-form" onsubmit="return search()">
<input type="search" id="query" class="search-field" value="<?php echo $searchQuery;?>">
<input type="submit" name="search-btn" id="search-btn" value="">
</form>
As you can see, in the search field (id=query
) I have a php which sometimes inserts value into his field.
What I want to do is following:
- If
$searchQuery
doesn't exist (or in other words, if value of search fieldid=query
is empty, allow user to click on the search button manually. - If
$searchQuery
exist, auto submit the the form (simulate click on the search button.
Any solution will help, JavaScript, jQuery or in PHP. I just need to figure out how to auto submit this form when PHP variable $searchQuery
exists.