0

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").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.

2
  • post the generated html instead of ASP server-side. Commented Aug 17, 2011 at 21:32
  • Looks right. Any chance your not passing client side validation, returning false on the form submit? Commented Aug 17, 2011 at 21:57

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for response, tried everything I can think of, given up.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.