Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  114] [ 5]  / answers: 1 / hits: 8769  / 10 Years ago, wed, november 19, 2014, 12:00:00

I have this button in a bootstrap modal dialog:



<button id=btnSelectAll style=float:left>Select All</button>


The click event looks like this, all it is supposed to do is mark a bunch of checkboxes as checked.



$(document).on('click', '#btnSelectAll', function ()
{
var $modal = $('#MyPanel');
$modal.find('#aCheckBox').prop('checked', true);

});


Here is the markup for the modal itself (with specifics removed as it's a bit long and basically just a bunch of checkboxes with a few buttons at the end):



   <asp:Panel class=modal ID=MyPanel runat=server>
<div class=modal-dialog modal-lg style=width:30%>
<div class=modal-content>
<div class=modal-header>
<asp:Label ID=Header runat=server Text=Header />
</div>
<div class=modal-body>
<table>
<tr>
<td style=width: 20px; />
<td>
<asp:Label ID=Label runat=server Text=Stuff: />
</td>
<tr>
</table>
</div>
</div>
</div>
</asp:Panel>


The click event code is being hit as I see it in the debugger, but the modal dialog always closes immediately when I click the button. I can't seem to find anything online to explain why, Googling just gives me a bunch of how do I close a modal on button click type questions. I want to know how to not close it.


More From » jquery

 Answers
0

You could just try e.preventDefault. From the jQuery documentation we have this



Description: If this method is called, the default action of the event
will not be triggered.



So, if you change your code to the following:


$(document).on('click', '#btnSelectAll', function (event)
{
event.preventDefault();
var $modal = $('#MyPanel');
$modal.find('#aCheckBox').prop('checked', true);
});

your problem will be solved.


[#41154] Tuesday, November 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myakylas

Total Points: 66
Total Questions: 85
Total Answers: 95

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
myakylas questions
Thu, Apr 28, 22, 00:00, 2 Years ago
Thu, Apr 8, 21, 00:00, 3 Years ago
Sat, Sep 19, 20, 00:00, 4 Years ago
;