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

100
Views
Proper way to set an AlpineJs variable using value from a select tag

I need to change the value of myData variable to whatever is the current value of the select tag.

I am currently using this and it works but is there a cleaner way in Alpine for doing this?

<div x-data="{ myData: []}">

    <select id="mySelect" @change="myData = document.getElementById('mySelect').value">
        <option>2021</option>
        <option>2022</option>
    </select>

</div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Figured it out using x-model. So the cleaner version of the above code is simply:

<div x-data="{ myData: []}">

    <select x-model="myData">
        <option>2021</option>
        <option>2022</option>
    </select>

</div>
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!