Calculating Machine Calculating Machine - 8 days ago 6
Ajax Question

click button not working in modal

I am generating modal box dynamically. In that modal i have two button. Yes & No.
No will close the modal and that is working properly.
I am facing problem while clicking on Yes button.

Once user click on Yes it will update the database.
Here is the code.

<script type="text/javascript">
$('document').ready(function(){
$("#btnYes1").on("submit", function(e) {
// $('#btnYes1').click(function (e) {
//$('#btnYes1').click(function() {
e.preventDefault();
alert('working');
});
});
</script>


Code used to generate Modal box. You can see i tried 2-3 things but it is not working.

var modalval='<a href="#" id="btnYes1" name="btnYes1" data-dismiss="modal" aria-hidden="true" class="btn btn-success">Yes</a>';
modalval += '<a href="#" data-dismiss="modal" aria-hidden="true" class="btn btn-danger">No</a>'; $('#modaltext').append(modalval);

Answer

Attach the event listener to your document instead.

$(document).on("click", "#btnYes1", function(e) {
    // Your code..
});