I have two select dropdowns. I am displaying the first dropdown on page load and the second dropdown is dynamically displaying.
Now what I am doing is, When the user selects anything from the first dropdown then the same option to be selected on the second dropdown after a click on the anchor tag.
I tried below code but there is some issue.
$(wrapper).append('<select name="pp_fileStatus[]" class="fileStatus"><option disabled="" selected="">Select</option><option value="1"'if(fileStatus==1){"selected";}'> One</option><option value="2"' if(fileStatus==2){"selected";}'> Two</option><option value="3"'if(fileStatus==3){"selected";}'> Three</option></select>');
$(document).ready(function() {
$('.fileStatus').change(function() {
var fileStatus = $('.fileStatus option:selected').val();
})
var wrapper = $(".appentInside .row"); //Fields wrapper
var add_button = $(".click_me"); //Add button ID
$(add_button).click(function(e) { //on add input button click
e.preventDefault();
$(wrapper).append('<select name="pp_fileStatus[]" class="fileStatus"><option disabled="" selected="">Select</option><option value="1"> One</option><option value="2">Two</option><option value="3"> Three</option></select>');
});
});
<select name="pp_fileStatus[]" class="fileStatus">
<option disabled="" selected="">Select</option>
<option value="1"> One</option>
<option value="2"> Two</option>
<option value="3"> Three</option>
</select>
<a href="javascript:void(0);" class="click_me">click me to display seocnd dropdown</a>
<div class="appentInside">
<div class="row"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>