tomindo Posted April 18, 2011 Share Posted April 18, 2011 I been working on search auto suggestion box which has one of function below. The function will fill the suggested result to search form field and submit the search but it will never submit the search. It really scratch my head on this issue, please help function fill(thisValue) { $('#country').val(thisValue); setTimeout("$('#suggestions').fadeOut();",100); $('#my_form').submit(); } Link to comment https://forums.phpfreaks.com/topic/234007-search-suggestion-box/ Share on other sites More sharing options...
nogray Posted April 18, 2011 Share Posted April 18, 2011 Without the html, we can't debug this problem. What's the action of your form? the .submit() will not fire the onsubmit event if you are using ajax. Link to comment https://forums.phpfreaks.com/topic/234007-search-suggestion-box/#findComment-1202840 Share on other sites More sharing options...
tomindo Posted April 18, 2011 Author Share Posted April 18, 2011 This is the html plus js script. It actually submits the form but with the empty field value <form id=my_form name=Form size=30 action=/search.php method=post> <div id="suggest"><br /> <input id=country maxlength=30 type=text name=key value="" onkeyup="suggest(this.value);" onblur="fill();" class=""> <div class="suggestionsBox" id="suggestions" style="display: none;"> <div class="suggestionList" id="suggestionsList"> </div> </div> </div> <input type=submit value='Search'> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script> <script type="text/javascript" language="JavaScript"> function suggest(inputString){ if(inputString.length == 0) { $('#suggestions').fadeOut(); } else { $('#country').addClass('load'); $.post("autosuggest.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions').fadeIn(); $('#suggestionsList').html(data); $('#country').removeClass('load'); } }); } } function fill(thisValue) { $('#country').val(thisValue); setTimeout("$('#suggestions').fadeOut();",100); $('#my_form').submit(); } </script> Link to comment https://forums.phpfreaks.com/topic/234007-search-suggestion-box/#findComment-1202863 Share on other sites More sharing options...
nogray Posted April 18, 2011 Share Posted April 18, 2011 I am not a jquery expret, but try to change $('#my_form').submit(); with document.getElementById('my_form').submit(); If still no luck, try to comment out the code inside the suggest function and comment out the 2 lines above the submit code to make sure nothing is causing an error in your code. Link to comment https://forums.phpfreaks.com/topic/234007-search-suggestion-box/#findComment-1203142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.