javascript - How to automatically submit form if input field value exists? -


i have following form on site. it's simple, 1 search input field , 1 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 can see, in search field (id=query) have php inserts value field.

what want following:

  • if $searchquery doesn't exist (or in other words, if value of search field id=query empty, allow user click on search button manually.
  • if $searchquery exist, auto submit the form (simulate click on search button.

any solution help, javascript, jquery or in php. need figure out how auto submit form when php variable $searchquery exists.

i believe asking on initial page load. use jquery:

$(document).ready(function() {    if ($('#query').val() !== '') {       $('#search-form').submit();    } }); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -