var $contentr = $('#contentr');
$contentr.on('click', '.addNewButton', function() {
var $removeButton = $('<input>');
$removeButton.attr('type', 'button');
$removeButton.addClass('removeButton');
$removeButton.val('Remove');
$newRow = $(this).closest('.rowWrapper').clone();
$newRow.append($removeButton).appendTo('#contentr');
$('.rowWrapper').last().find('.marklocation').trigger('change');
});
$contentr.on('click', '.removeButton', function() {
$(this).closest('.rowWrapper').remove();
});
$contentr.on('change', '.marklocation', function(event) {
$this = $(event.target);
var value = $this.val();
var $markingtype = $this.closest('.rowWrapper').find('.markingtype');
$markingtype.empty();
options.filter((opt) => {
return opt.runways.includes(value) || opt.runways.includes('default');
}).forEach((opt) => {
var $newOption = $('<option>');
$newOption.val(opt.value);
$newOption.text(opt.text);
$markingtype.append($newOption);
});
});
var options = [{
text: '- Marking Runway Types -',
value: 't',
runways: ['default']
}, {
text: 'Runway Designator Marking',
value: 'Runway Designator Marking',
runways: ['Runway 35', 'Runway 18', 'Runway 36']
},
{
text: 'Runway Centerline Marking',
value: 'Runway Centerline Marking',
runways: ['Runway 35', 'Runway 18', 'Runway 36']
},
{
text: 'Runway Threshold Marking',
value: 'Runway Side Strip Marking',
runways: ['Runway 35', 'Runway 18', 'Runway 36']
},
{
text: 'Runway Side Strip Marking',
value: 'Runway Side Strip Marking',
runways: ['Runway 35', 'Runway 18', 'Runway 36']
},
{
text: 'Runway Aiming Point Marking',
value: 'Runway Aiming Point Marking',
runways: ['Runway 35', 'Runway 18', 'Runway 36']
},
{
text: 'Runway Touchdown Zone Marking',
value: 'Runway Touchdown Zone Marking',
runways: ['Runway 35', 'Runway 18', 'Runway 36']
},
{
text: 'Runway Displaced Threshold Marking',
value: 'Runway Displaced Threshold Marking',
runways: ['Runway 35', 'Runway 18', 'Runway 36']
},
{
text: 'Chevron Markings For Stopway',
value: 'Chevron Markings For Stopway',
runways: ['Runway 35', 'Runway 18', 'Runway 36']
},
];
.rowWrapper {
border: 1px solid black;
padding: 10px;
margin: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="contentr">
<div class="rowWrapper">
<select class="marklocation" name="marklocation[]" style="width: 42%">
<option value="">- Location -</option>
<option value="Runway 17">Runway 17</option>
<option value="Runway 35">Runway 35</option>
<option value="Runway 18">Runway 18</option>
<option value="Runway 36">Runway 36</option>
</select><br/>
<select class="markingtype" name="markingtype[]" style="width: 42%">
<option value="">-- Marking Type -- </option>
</select><br/>
<select class="tdmPassport" name="tdmPassport[]" style="width: 42%" class="auto-style2">
<option value="">- Marking Condition -</option>
<option value="Good:Accepted Level" style="background-color: #29BB29">Good</option>
<option value="Medium:Maintenance Plan Level" style="background-color: yellow">Medium</option>
<option value="Poor:Corrective Action Level" style="background-color: #FE4E4E">Poor</option>
</select><br>
<p class="auto-style3">Maintenance Plan:</p>
<textarea class="markingplan" name="markingplan[]" style="width: 572px; height: 129px"></textarea>
<br>
<input class="addNewButton" type="button" value="Add new"><br>
</div>
</div>