Привет, я новичок в php, и я нашел select2 для автоматического заполнения выпадающего меню, я хотел бы использовать его внутри модального режима, первый select2 внутри его модального режима работает, но второй не работает, вот мой код для ПЕРВЫЙ (рабочий)
HTML:
<div id="prevprojmodal" class="modal fade" role="dialog" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<select class="substat form-control" style="width:500px" name="substat" style="min-width: 100%"></select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
JS
<script type="text/javascript">
$('.substat').select2({
allowClear: true,
placeholder: 'Type to search for previous project',
ajax: {
url: 'ajax/getdata_previousproject.php',
dataType: 'json',
delay: 250,
processResults: function (data) {
return {
results: data
};
},
cache: true
}
});
$('.substat').on('change', function() {
var data = $(".substat option:selected").text();
$("#projectprevioustest").val(data);
})
</script>
И это код второго, но НЕ РАБОТАЕТ:
HTML
<!-- Add Team Compo Modal -->
<div class="modal fade" id="addteamcompomodal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Add a member to Team</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="form-group">
<label> Staff Name </label>
<select class="staffname form-control" name="staffname" id="staffname" placeholder="Staff Name" style="width: 100%; padding: 0;"></select>
</div>
<div class="form-group">
<label> Percent Involvement </label>
<input type="text" name="teampi" id="teampi" placeholder="Percent Involvement" class="form-control">
</div>
<div class="form-group">
<label> Specific Duties & Responsibilities </label>
<input type="text" name="teamsdnr" id="teamsdnr" placeholder="Specific Duties & Responsibilities" class="form-control">
</div>
<div class="form-group">
<label> Specific Deliverables </label>
<input type="text" name="teamsd" id="teamsd" placeholder="Specific Deliverables" class="form-control">
</div>
<div class="form-group">
<label> Project Role </label>
<select required="" name="teampr" class="form-control" style="font-size: 12px;">
<?php
$resultatc = $pdo->prepare("SELECT * FROM teamroles");
$resultatc->execute();
$checkRtc = $resultatc->rowCount();
if ($checkRtc > 0) {
echo "<option disabled='disabled' value = '' selected>SELECT</option>";
foreach ($resultatc->fetchAll(PDO::FETCH_BOTH) as $disptc) {
for ($z = 0; $z < count($checkRtc); $z++) {
$disp_idtc = $disptc['tr_id'];
$disp_statustc = $disptc['tr_abb'];
}
echo "<option value='" . $disp_idtc . "'>" . utf8_encode($disp_statustc) . "</option>";
}
}
?>
</select>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal" onclick="addRecord()">Save</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Add Team Compo Modal END-->
JS
<script type="text/javascript">
$(document).ready(function() {
$('.staffname').select2({
dropdownParent: $('#addteamcompomodal')
allowClear: true,
placeholder: 'Type to Search for Staff',
ajax: {
url: 'ajax/getdata_staffteamcomp.php',
dataType: 'json',
delay: 250,
processResults: function (data) {
return {
results: data
};
},
cache: true
}
});
</script>
Что я должен делать не так? Заранее спасибо.