How do I set the value of a select dropdown based on the selection in another dropdown, using jQuery?

I have this select dropdown where I will make my first choice:

<div class="col-sm-12">
		  	 <select class="form-control nomeassociazione" onchange="assoc_zone(this,  '');" id="input-assoc_lists" name="custom_field[account][15]">
				<option value="0"> --- Seleziona --- </option>
								
				<option value="149">FAS - Fondo Ambiente Sammarinese</option>

				<option value="12">Polisportiva Stella S.G.</option>
												
				<option value="119">ACLI Associazioni Cristiane Lavoratori Italiani</option>

		  	 </select>

</div>

Open in new window



and this is my second select dropdown:

<div class="col-sm-12">
			 <select class="form-control" id="input-assoc_list" name="custom_field[account][21]">

			<option value="152">Associazione di volontariato "Madonna della Carità"</option>

			<option value="149">FAS - Fondo Ambiente Sammarinese</option>
									
			<option value="12">Polisportiva Stella S.G.</option>
									
			<option value="119">ACLI Associazioni Cristiane Lavoratori Italiani</option>

			 </select>
</div>

Open in new window



What I am trying to achieve is that if in dropdown one I choose the value: "FAS - Fondo Ambiente Sammarinese" then in dropdown two I need the same value to be chosen.

How do I achieve this using jQuery?

thanks in advance
badwolfffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I use jquery chained for this.  Look at their code sample below.  You can see the value of the first set of options is keyed on the class of the second. This is very easy to use.

http://www.appelsiini.net/projects/chained

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="jquery.chained.min.js"></script>
<select id="mark" name="mark">
  <option value="">--</option>
  <option value="bmw">BMW</option>
  <option value="audi">Audi</option>
</select>
<select id="series" name="series">
  <option value="">--</option>
  <option value="series-3" class="bmw">3 series</option>
  <option value="series-5" class="bmw">5 series</option>
  <option value="series-6" class="bmw">6 series</option>
  <option value="a3" class="audi">A3</option>
  <option value="a4" class="audi">A4</option>
  <option value="a5" class="audi">A5</option>
</select>

Open in new window

0
badwolfffAuthor Commented:
No can do as I did not write the php that is generating this. My job is to find a quick fix :(

Can I not search for the entire string. They are identical in both cases.

thanks
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
$('select#input-assoc_lists').change(function(){
        var n = $(this,' option:selected').val();
       $('select#input-assoc_list').val(n);
});

Open in new window

http://jsbin.com/pogexopeqi/edit?html,output
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <script>
    $(function(){
      $('select#input-assoc_lists').change(function(){
  var n = $(this,' option:selected').val();
  $('select#input-assoc_list').val(n);
});
    });
  </script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div class="col-sm-12">
		  	 <select class="form-control nomeassociazione" onchange="assoc_zone(this,  '');" id="input-assoc_lists" name="custom_field[account][15]">
				<option value="0"> --- Seleziona --- </option>
								
				<option value="149">FAS - Fondo Ambiente Sammarinese</option>

				<option value="12">Polisportiva Stella S.G.</option>
												
				<option value="119">ACLI Associazioni Cristiane Lavoratori Italiani</option>

		  	 </select>

</div>

  
  
  <div class="col-sm-12">
			 <select class="form-control" id="input-assoc_list" name="custom_field[account][21]">

			<option value="152">Associazione di volontariato "Madonna della Carità"</option>

			<option value="149">FAS - Fondo Ambiente Sammarinese</option>
									
			<option value="12">Polisportiva Stella S.G.</option>
									
			<option value="119">ACLI Associazioni Cristiane Lavoratori Italiani</option>

			 </select>
</div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.