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

180
Views
How to sync a data attribute value of an autocomplete datalist using Alpine.js?

On submit, I would like to get the POST value of company, which matches the ID (from data-id) of the selected value:

<form method="post" x-data="{ company: '' }">
    <input type="hidden" name="company" x-bind:value="company">
    <input list="companies" x-model="company">
    <datalist id="companies">
        <option data-id="1">Google</option>
        <option data-id="2">Amazon</option>
        <option data-id="3">Facebook</option>
        <option data-id="4">Apple</option>
    </datalist>
    <input type="submit">
</form>

Like this, I get the input[list="companies"] value, but not the data-id value of the selected option.

How can I sync the data-id value to the input[name="company"] hidden field?

about 4 years ago · Juan Pablo Isaza
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!