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

255
Views
How to use the selected id of a dropdown in Vue.js in a button outside of option/select tag loop

I am trying to add a button that get the id of the selected list of restaurants so i can pass that id to my API request whenever i click on my button. However, i cannot add my button to the select because it disappear and i seem to be outside of the option loop in order to retrieve the id.

<div id="selectedList" class="addFavoriteRestaurantToList">
        <select  name="list_id" @change="onChange($event)" class="form-control">
              <option>--- Select a fav list ---</option>
              <option :key="listresto.id"  v-for="listresto in favoriteRestaurantData"> {{listresto.name}}</option>
        </select>
       <button class="removeButton" @click="AddFavoriteRestaurant( listresto.id, restaurantData.id)"> Add "{{restaurantData.name}}" to your your favorite list</button>
</div>

method used to return what i selected in dropbox (works but since i cant use anything on my button, im stuck) :

onChange(event) {
  return event.target.value;
}

So what i want it to get the id of the selected list to use it on my button.

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

0

<div id="selectedList" class="addFavoriteRestaurantToList">
        <select v-model="list_id" name="list_id" @change="onChange($event)" class="form-control">
              <option>--- Select a fav list ---</option>
              <option :key="listresto.id" :value="listresto.id"  v-for="listresto in favoriteRestaurantData"> {{listresto.name}}</option>
        </select>
       <button class="removeButton" @click="AddFavoriteRestaurant( list_id, restaurantData.id)"> Add "{{restaurantData.name}}" to your your favorite list</button>
</div>

and v-model="list_id" declare list_id in data:({list_id:''})

don't forget line with :value="listresto.id"

<option :key="listresto.id" :value="listresto.id"  v-for="listresto in favoriteRestaurantData"> {{listresto.name}}</option>
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!