views:

14

answers:

3

I have a form in which I have many checkboxes. I need to post the data to the controller upon any checkbox checked or unchecked, i.e a click on a checbox must post to the controller, and there is no submit button. What will be the bet method in this case? I have though of Ajax.BeginForm and have the codes below. The problem im having is that the checkbox click event is being detected only once and after that the click event isnt being launched. Why is that so? How can I correct that?

<% using (Ajax.BeginForm("Edit", new AjaxOptions { UpdateTargetId = "tests"}))
         {%>
               <div id="tests">
                    <%Html.RenderPartial("Details", Model); %>
               </div>
                <input type="submit" value="Save" style="Viibility:hidden" id="myForm"/> 
          <%}
          %>

$(function() {
 $('input:checkbox').click(function() {
        $('#myForm').click();
    });
  });
A: 

Try $('#myForm').submit().

Ken Redler
A: 

Check this post out. I think you need to use the each keyword and bind so that binding is done everytime.

griegs
A: 

As a debugging step, try doing something else during the click event, like

$('input:checkbox').click(function() {
    $('#debugDiv').append('click event fired at ' + new Date().toString());
});

to see if the issue has something to do with the form submission.

Something else you can try is using jQuery's live function instead of click: http://api.jquery.com/live/

Jeff Schumacher
Simply the live keywoed has solved the problem. Thank you.$("input:checkbox").live('click', function(){ $('#myForm').click(); }); });