I have a dropdown category lists from taxonomy, how could I display the selected category name inside the dropbox when it’s selected/ active?
here is dropdown category code bellow:
<select id="categ" name="categ">
<div class="options">
<option value="<?php echo home_url('/newsletter'); ?>" selected>一覧</option>
<?php
$args = array(
'orderby' => 'slug',
'order' => 'ASC',
'parent' => 0,
'hide_empty' => false
);
$terms = get_terms([
'taxonomy' => 'pdf_cat',
'hide_empty' => false,
]);
foreach( $terms as $term ){
echo '<option class="ctg" value="'. get_term_link($term->term_id) .' ">' . $term->name . '</option>';
}
?>
</div>
</select>
JS code when URL fired:
<script type="text/javascript">
$("#categ").change(function(){
var url = $(this).val();
location.assign(url);
});
</script>