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

148
Views
How to pass the value of a component up to its parent?

I want to bind the value of a select element in a Svelte component (Form.svelte) to the variable active in its parent (App.svelte). I've tried using bind:value={active} on the Form component in App, but this doesn't work because I need to access the select's value. How should I access the value of the select element? Thanks in advance.

Minimum working example: https://svelte.dev/repl/bc872132e21f4071abe5a255728fb0ec?version=3.43.0

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

0

You need to expose the value property if you want to bind to it. Here, we also bind the value property to the select element so that it is updated with changes to the select.

/* Select.svelte */

<script>
    export let value
</script>

<select bind:value>
    <option value="1">one</option>
    <option value="2">two</option>
    <option value="3">three</option>
</select>

You can then bind to it in your parent

/* App.svelte */

<script>
    import Select from './Select.svelte'
    
    let active;
</script>

<Select bind:value={active}/>

<p>{active}</p>

REPL

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!