scooti
scooti

Reputation: 51

Changing select will change another SELECT with same previous value

i need help with my code. I have a lot of Select inputs

<select title="" name="width[]">
<option value="8">3mm</option>
<option value="1">10mm</option>
<option selected="" value="4">18mm</option>
</select>

and when I change one of them I need to change values in all selects where was same value.

for example

1. select with value 8
2. select with value 8
3. select with value 4
4. select with value 8
5. select with value 4

and when I change second SELECT with value 8 to value 1, I need to change 1. and 4. SELECTs and change their values to 1.

Thanks a lot

Upvotes: 0

Views: 122

Answers (1)

Neeraj
Neeraj

Reputation: 4489

$(".ddl").change(function() {  
var ddl1=$(this);   
$('select[id^=begin_]').each(function(){
    var DDLId=$(this).attr('id');
    $('#' + DDLId + ' option').each(function(){              

    if ($(this).val() == ddl1.val()) 
    {               
        $(this).val(ddl1.val()).attr('selected','selected');
    }

  });

  });   
});

Live Demo

Upvotes: 1

Related Questions