Select an item in CascadingDropDown with JavaScript & invoke update

In encoding, I can do this to select something:

// Select item in first DropDownList
myCascadingDropDown_1.SelectedValue = itemValue_1+":::"+itemText_1;

// Select item in second DropDownList
myCascadingDropDown_2.SelectedValue = itemValue_2+":::"+itemText_2;

How can i do this in javascript?

(I know that I could search the list and set the selectedIndex property for each drop-down list, but I have a lot of elements, and I'm very lazy.)

EDIT:

Answers to npups: I can select the desired item in the first drop-down list. The problem, however, is that the new values ​​based on the selected item (this is CascadingDropDown, remember?) Do not appear in the second drop-down list, so I cannot select anything there. I need to somehow call the update method of the second drop-down menu manually: any suggestions?

+3
3

:

<select id="foo">
  <option value="bar">bar</option>
  <option value="baz">baz</option>
  <option value="bork">bork</option>
</select>

<script type="text/javascript">
  var selectElem = document.getElementById('foo');
  selectElem.value = 'baz';
</script>

select .

Firefox , ( ). .

, :
, - ( ), ?

onchange. " ", onchange . , , . ( ) .

<select id="foo" onchange="harmonize();">
  <option value="bar">bar</option>
  <option value="baz">baz</option>
  <option>bork</option>
</select>

<select id="foo2">
 <option value="0">This</option>
 <option value="1">That</option>
</select>


<script type="text/javascript">
   var select0 = document.getElementById('foo');
   var select1 = document.getElementById('foo2');
   select0.value = 'baz';
   // alternative 1: call harmonize();
   // alternative 2: call select0.onchange();

   function harmonize() {
     if (select0.value==='baz') {
       select1.value = '1';
     }
     else {
       select1.value = '0';
     }
   }
</script>

.., , , .

+1

:

1) npups "myCascadingDropDown_1" .

2)

myCascadingDropDown_2.CascadingDropDownBehavior._onParentChange (, );

"myCascadingDropDown_1".

3) , , , ( npups ).

+2

myCascadingDropDown_2.set_SelectedValue (resultval, resultVal) (item3)

0
source

Source: https://habr.com/ru/post/1737364/


All Articles