2

I have a button and im trying to fire the function below on click of "Duplicate". Could you guide me through the right way?

Currently, when i click nothing happens! There is no response. I need to fire the function on click.

Thanks in advance

JS

$(document).on('click', '.js-duplicateRoom', function (e) {
 var hiddenInput = $(this).parent().find('input[name="roomId"]');
 var roomId = hiddenInput.data('id');
 var type = 'duplicate';
 $.ajax({
 type: "GET",
 url: "/management/hostaccommodation/AddRoom?roomId=" + roomId + '&type=' + type,
 }).done(function (result) {
 $('#addRoomResult').html(result);
 // Hide Add Room Button
 $('#addNewRoom').hide();
 $('#backToDetails').hide();
 $('#nextPropertyExtras').hide(); // Next button
 });
 });

HTML

<div class="modal fade" id="duplicateModal" tabindex="-1" role="dialog" aria-labelledby="duplicateModalLabel" aria-hidden="true">
 <div class="modal-dialog" role="document">
 <div class="modal-content">
 <div class="modal-header">
 <h5 class="modal-title" id="duplicateModalLabel">Confirm Duplicate</h5>
 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
 <span aria-hidden="true">&times;</span>
 </button>
 </div>
 <div class="modal-body">
 <p>Are you sure you would like to duplicate this Room?</p>
 </div>
 <div class="modal-footer">
 <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Cancel</button>
 <button type="button" class="btn btn-success" id="js-duplicateRoom" >Duplicate</button>
 </div>
 </div>
 </div>
</div>
asked Oct 11, 2020 at 23:07
1
  • 2
    This is a typo. .js-duplicateRoom should be #js-duplicateRoom Commented Oct 11, 2020 at 23:08

1 Answer 1

3

The button is identified by an ID, not a class. So try this instead:

$(document).on('click', '#js-duplicateRoom', function(e) {
 var hiddenInput = $(this).parent().find('input[name="roomId"]');
 var roomId = hiddenInput.data('id');
 var type = 'duplicate';
 $.ajax({
 type: "GET",
 url: "/management/hostaccommodation/AddRoom?roomId=" + roomId + '&type=' + type,
 }).done(function(result) {
 $('#addRoomResult').html(result); // Hide Add Room Button
 $('#addNewRoom').hide();
 $('#backToDetails').hide();
 $('#nextPropertyExtras').hide(); // Next button
 });
});

evolutionxbox
4,1426 gold badges40 silver badges59 bronze badges
answered Oct 11, 2020 at 23:16
Sign up to request clarification or add additional context in comments.

2 Comments

Please may you flag the question as a typo instead of answering?
Perfect and so Clear.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.