Jump to content

search suggestion box


tomindo

Recommended Posts

 

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.