开发者

Auto submit MVC form with jQuery when drop downs change not working

I wonder if someone can shed some light why my form would not submit with the following script. I need the from to submit as soon as the drop-down changed.

<script type="text/javascript">
$(document).ready(function () {
    $("select")开发者_如何学JAVA.change(function () {
        $("#sform").submit(); // Trigger form load
        //alert('form to reload!');
    });

});

And the form something like this:

@using (Html.BeginForm("ServiceNumbers", "Home", FormMethod.Post, new { id = "sform" }))
{
  <div> Companies:
    @Html.DropDownListFor(model => model.CompanyID, Model.CompaniesList, "")
  </div>
}

The commented out alert triggers when uncommented, the form itself does not submit. I am obviously doing something wrong, or maybe this cannot work for some reason? Related posts have not shed any light so far, still searching.

Thanks in advance.

EDIT:

I tried most of the items in this post. None seems to work.

I can make the whole form disappear with:

$(document).ready(function () {
    $("select").change(function () {
        //$("form#sform").submit(); // Trigger form load
        //alert('form to reload! len=' + $("#sform").length);
        //document.forms["sform"].submit();
        //document.sform.submit();
        $("form#sform").html("");
    });

But submit - no way. The only conclusion I can get to is that it has something to do with the MVC modernizr-1.7.min.js script.


Can you alert $("#sform").length and see? I suspect the form id is not the same when it is rendered on the page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜