Currently I have 2 dropdown boxes with the same options. These options are all filled from the backend. Now I want it so that whenever I choose 1 option in the dropdown box, the other dropdown also automatically chooses the same value and this works both ways. The following is my dropdown box code:
<select name="lead_status" id="leadstatus" class="form-control">
<option value="">Select</option>
<?php foreach($leadstatus as $key => $status): ?>
<option value="<?php echo $key; ?>" <?php echo $key==$lead->lead_status?'selected="selected"':'' ?>><?php echo $status; ?></option>
<?php endforeach; ?>
</select>
<select name="lead_status" id="leadstatus2" class="form-control">
<option value="">Select</option>
<?php foreach($leadstatus as $key => $status): ?>
<option value="<?php echo $key; ?>" <?php echo $key==$lead->lead_status?'selected="selected"':'' ?>><?php echo $status; ?></option>
<?php endforeach; ?>
</select>
I’ve tried creating a function for onclick where it creates a check saying:
if (document.getElementById('leadstatus').value == '1')
document.getElementById("leadstatus2").value = '1';
But this wont work since I have a lot of data in the dropdown lists and it is dynamic.