简体   繁体   中英

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM