Answers for "How to select selected on an option based on its value using jQuery"

-1

How to select selected on an option based on its value using jQuery

<div class="form-group">
    <label for="unit-department">Unit / Department</label>
    <select class="form-control" id="unit-department" name="unit-department" required="required">
        <option value="">...</option>
        @foreach ($unitDepartment as $item)
        <option value="{{ $item->kode_unit }}">{{ $item->nama }}</option>
        @endforeach
    </select>
</div>

<script>
$(document).ready(function(){
  $("#unit-department > option[value='HRD']").attr("selected","selected");
});
</script>

// Application of coding using laravel

<script>
$(document).ready(function(){
  $("#unit-department > option[value='HRD']").attr("selected","selected");
});
</script>
Posted by: Guest on October-24-2021

Code answers related to "How to select selected on an option based on its value using jQuery"

Browse Popular Code Answers by Language