开发者

Prototype set selected option based on other select

开发者 https://www.devze.com 2022-12-27 05:42 出处:网络
how can I \"copy\" the selected option between two s that have the same options using prototype ? I tried getting the selected option from the \"master\" combo using

how can I "copy" the selected option between two s that have the same options using prototype ? I tried getting the selected option from the "master" combo using

function getSelectedArea() {
  $$('#areacont1 option').find(function(ele){return !!ele.selected})
}

which returns null

And setting the second combo using

var c2ROptions = $$('select#areacont2 option')
c2ROptions[getSelectedArea()].selected = true

That obviously doesn't work because the function returns null.

Any hin开发者_JAVA技巧ts?

Thanks.


$('option1').observe('change', function() {
    $('option2').value = $F('option1');
});

What this code does is observe dropdown1 (that's the id of the dropdown) and when its value changes dropdown2 is update to reflect the same value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号