views:

79

answers:

3

Hello,

I'm building an intranet site for work with an autocomplete feature. I have it working to where when the user clicks on the name in the autocomplete list, it will fill that value to the text input box. What I need it to do is after it fills in the value, also submit the form, à la Google. I know I have to use document.formname.submit, but I can't get it to do both, all I can get is one or the other. I would usually research how to do this, but I'm on a tight schedule and really need your help! Here's what I have for the code so far.

function suggest(a) {
    if (a.length == 0) {
        $("#suggestions").fadeOut()
    } else {
        $("#search").addClass("load");
        $.post("autosuggest.php", {
            queryString: "" + a + ""
        },

        function (b) {
            if (b.length > 0) {
                $("#suggestions").fadeIn();
                $("#suggestionsList").html(b);
                $("#search").removeClass("load")
            }
        })
    }
}
function fill(a) {
    $("#search").val(a);
    setTimeout("$('#suggestions').fadeOut();", 300)
};
+2  A: 

What about:

$("#form_name").trigger("submit"):
ryanulit
+1  A: 

'submit' is a method, so you'll be wanting to put brackets after it in order to actually do anything:

document.formname.submit()

Since you're using jQuery anyway, you're better off sticking with the event stuff you get with that, it's much more powerful if you need to do more complicated things later on.

In this instance you'll have to give your form an ID attribute (if there isn't one already) and use:

$('#idOfForm').trigger('submit');
xiani
A: 

You need to call document.formname.submit() or $("#form-id").submit() at the callback handler of the $.post method. Is that what you are doing now?

kgiannakakis