开发者

jQuery one click, two actions. Help!

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");
        $.p开发者_如何学编程ost("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)
};


What about:

$("#form_name").trigger("submit"):


'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');


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜