Something like this will work:
$('.statusButtonChange').change(function () {
if ($(this).val() == '1') changeStatus($(this).attr('data-value'));
else if ($(this).val() == '3') openModal($(this).attr('data-value'));
else changeWork($(this).attr('data-value'));
});
…
function openModal(x) {
$('#alarm-' + x).modal('show');
}
I have a select input dropdown that calls a function (openModal) when the “3” value is selected:
$('.statusButtonChange').change(function () {
if ($(this).val() == '1') changeStatus($(this).attr('data-value'));
else if ($(this).val() == '3') openModal();
else changeWork($(this).attr('data-value'));
});
This is my openModal function:
function openModal(x) {
(function ($) {
$('#alarm-DATAVALUEOFTHESELECTOPTIONTHATTRIGGEREDTHISFUNCTION').modal('show');
})(jQuery);
}
And my html:
<select class="statusButtonChange statusButton " data-value="46024">
<option value="0" selected=""></option>
<option value="1">Close</option>
<option value="2">Open</option>
<option value="3">Disable</option>
</select>
<div id="alarm-'.$element['eventId'].'" class="modal fade modal-alert">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Title
</div>
<div class="modal-body" id="boxPopUpPushCommand" style="text-align:left !important">
Body texts here
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
I have multiple modals, with different div ids, depending on the data-value from my PHP code. Data-value can also be taken from the data-value inside my select html. Is there a way to get the data-value of the select option where i triggered the change() function? I’m not sure if I made sense but I hope you get what I mean. I want to be able to show just the modal of a certain data-value where I did the select.