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

127
Views
how I can get the ID of the selected option from a dynamically created dropdown using PHP, or Jquery?

I use this code in fetching the data from the database.

$result = $con->query("SELECT firstname,lastname FROM employee");

And then render like bellow:

            <select name="employees">
                <option value="">Select Employee</option>
                <?php while ($rows = $result->fetch_assoc()) {
                    $employee_name = $rows['firstname'] . " " . $rows['lastname'];
                    echo "<option id = emprecord_id value = '$employee_name'>$employee_name</option>";
                }  
            ?>
        </select>

I need to know how can I get the ID (or if there is anyway) of the selected value because I will insert values for the selected option in another table. Like i get the data from the employee table and If the Name of the employee was selected, it will proceed to another page we're I will insert new data for its payroll.

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

0

You could access the selected option with selectedIndex :

let tSelectedIndex = document.querySelector('select[name=languages]').selectedIndex;
let tID = document.querySelectorAll('select[name=languages] option')[tSelectedIndex].id;
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!