html - GET request to same page- jQuery form -


i building small search engine, using form like

form action="" method="get" id="searchform"> <input type="search" name="search" id="searchquery" value="<?php echo $_get['search']; ?>" /> </form>  

i passing search query same page. want prevent submitting form if text box value null. so, added event handler form

$('#searchform').submit(function() { alert('handler .submit() called.'); if($('#searchquery').val()==null) { return false; } });  

but doesnt seem work, when try using form action ="#" works fine. can suggest workaround?

instead of checking against null, trim value , check against empty string.

$('#searchform').submit(function(event) {  if($('#searchquery').val().trim()=="")  {   return false;  } });  

note: using trim() ensures form doesn't submit if whitespace in input text box.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -