Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Filling up one dropdown with same value of the other

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.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Since the question mentions... ...the other dropdown also automatically chooses the same value and this works both ways...

Try the following, ..

const leadStatusList = document.getElementById('leadstatus');
const leadStatus2List = document.getElementById('leadstatus2');

const setDropdownValue = (event) => {
  leadStatusList.value = event.target.value;
  leadStatus2List.value = event.target.value;
}

leadStatusList.onchange = setDropdownValue;
leadStatus2List.onchange = setDropdownValue;
about 4 years ago · Juan Pablo Isaza Report

0

Simply set the second dropdown's selectedIndex property to that of the first dropdown:

let box1 = document.getElementById("box1");
let box2 = document.getElementById("box2");
box1.addEventListener("change", () => {
  box2.selectedIndex = box1.selectedIndex;
});
box2.addEventListener("change", () => {
  box1.selectedIndex = box2.selectedIndex;
});
<select id="box1">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
  <option value="4">Option 4</option>
  <option value="5">Option 5</option>
</select>
<select id="box2">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
  <option value="4">Option 4</option>
  <option value="5">Option 5</option>
</select>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!