php - modal, button on modal executing many time -
i trying send data on button on modal using jquery, first time working when click second time execute twice , third time execute 3 times, want execute button once, wrong exactly? modal
`<div id="modal" class="modal fade" role="dialog"> <div class="modal-dialog"> <div class="modal-content modal-sm"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">product</h4> </div> <div class="modal-body"> <label>quantity</label> <input type="text" class="form-control" id="qty" value=""> <label>note:</label> <input type="text" class="form-control" id="note" value=""> </div> <div class="modal-footer"> <button id="" type="button" class="btn btn-primary mdismiss" data-dismiss="modal">add</button> </div> </div> </div> </div>`
my jquery :
`
$('#btnbtn').click(function(){ $('#modal').modal('show'); $('#addbutton').click(function(){ alert(); }); });`
you adding click
handler multiple time whenever clicking on #btnbtn
button. no need of attaching click
event handler #addbutton
on each click. change code below:
$('#btnbtn').click(function(){ $('#modal').modal('show'); }); $('#addbutton').click(function(){ alert(); });
Comments
Post a Comment