user819719
user819719

Reputation:

drop down box using jquery

I have two drop down boxes.One drop box has values as may the other as 1.Now i change the first drop down value to june but will not change second drop box value.Here it is not passing second drop box because i have initiated using click event.Here i use live(click)but do i do that w/o clicking 2nd drop box that value should also pass

 **Updated**

 $(firstselect).live(click,function)
 $(secondselect).live(click,function)

Upvotes: 0

Views: 533

Answers (1)

Felix Kling
Felix Kling

Reputation: 816262

Now that I understood the problem:

The second select box should show the value that was previously selected in the first one.

You could do like so:

var prevValue = $('#firstselect').val();

$('#firstselect').change(function() {
   $('#secondselect').val(prevValue);
   prevValue = this.value;
});

DEMO

Bidirectional:

var prevValue = {
    'firstselect':  $('#firstselect').val(),
    'secondselect':  $('#secondselect').val()
};

$('select').change(function() {
    var other = this.id === 'firstselect' ? 'secondselect' : 'firstselect';

    prevValue[other] = $('#' + other).val();
    $('#' + other).val(prevValue[this.id]);
    prevValue[this.id] = this.value;
});

DEMO 2

Upvotes: 1

Related Questions