Mazeltov
Mazeltov

Reputation: 551

Jquery change the value of dropdown from a dropdown change

I'm trying to change the value of two dropdown lists when a third one changes, to that dropdown's new value:

<script>
$('select[name="d1"]').change(function() {
  $('select[name="d2"]').val(this.value);
  $('select[name="d3"]').val(this.value);
});
</script>

Nothing happens.

Upvotes: 0

Views: 64

Answers (2)

Anoop Joshi P
Anoop Joshi P

Reputation: 25527

Try like this

$(function() {

    $('select[name="d1"]').change(function() {
        $('select[name="d2"]').val($(this).val());
        $('select[name="d2"]').html($(this).val());
    });

});

Upvotes: 0

Rey Libutan
Rey Libutan

Reputation: 5314

Try this for starters, work your way when you get this to work :)

$(document).ready(function() {
   $('select[name="d1"]').change(function() {
      $('select[name="d2"]').val(this.value);
      $('select[name="d3"]').val(this.value);
   });
});

Upvotes: 3

Related Questions