Get the index of a single choice field dropdown
Hi,
We have a two choice dropdown fields in a custom SharePoint list with the same number of choices in each field, one for the item, and one for the unit cost of the item.
We are trying to get the form to automatically pick the choice from the 2nd dropdown based on a selection in the first. For example, if the first choice is selected in the first dropdown, the first choice is selected in the 2nd dropdown, etc etc (1 to 1 relationship).
Is this possible? How can we get the index of the single choice dropdown and use that to set the value of the 2nd choice dropdown?
Thanks in advance.
We have a two choice dropdown fields in a custom SharePoint list with the same number of choices in each field, one for the item, and one for the unit cost of the item.
We are trying to get the form to automatically pick the choice from the 2nd dropdown based on a selection in the first. For example, if the first choice is selected in the first dropdown, the first choice is selected in the 2nd dropdown, etc etc (1 to 1 relationship).
Is this possible? How can we get the index of the single choice dropdown and use that to set the value of the 2nd choice dropdown?
Thanks in advance.
To get selected item's index:
To set a select's selected item by index:
If you want to set your dropdown box No. 2 to the value of the dropdown box No.1 when the No.1 changes selected item, you can use the change event, like this:
Code: Select all
fd.field('dropdown1').control()._el().find('select')[0].selectedIndex
Code: Select all
fd.field('dropdown2').control()._el().find('option').eq().prop('selected', true);
Code: Select all
fd.field('dropdown1').change(function(){
var selectedIndex = fd.field('dropdown1').control()._el().find('select')[0].selectedIndex;
fd.field('dropdown2').control()._el().find('option').eq(selectedIndex).prop('selected', true);
});
-
- Information
-
Who is online
Users browsing this forum: No registered users and 25 guests