Hi All,
I'm having multi select webdropdowns and on selectedindexchanged event i need to add the VALUE fields to a string, But i'm not able to get the VALUE fields of webdropdown rather i'm getting the INDEX i,e if 1st and 5th items are selected in the dropdown i'm getting the values 1, 5..
I tried using get_currentValue() but it is throwing an error object of type not supported.. Below is the script for that, Kindly look into this..
<code>
for (i = 0; i < newItems.length; i++) { if (sender._id == "cph1_ddlPC") { if (newItems[i].get_index() < 10) { newItemsString += "0" + newItems[i].get_currentValue() + ", "; } else { newItemsString += newItems[i].get_currentValue() + ", "; } } else { newItemsString += newItems[i].get_currentValue() + ", "; } }
</code>
Hi pavanpuligandla,
From the eventArgs of client-side SelectionChanged event handler you could get the array of selected items and their text or value, using the following syntax:
function WebDropDown1_SelectionChanged(sender, eventArgs) {
var text = eventArgs.getNewSelection()[0].get_text();
var value = eventArgs.getNewSelection()[0].get_value();
}
Please let me know if this helps.
How do you determine which item of a multi-select dropdown was most recently selected? Let's say I have a multiselect WebDropDown control with the following items:
A, B, C, D
I click on A and C in that order. eventArgs.getNewSelection()[0].get_text() will give me "A". The eventArgs.getNewSelection()[1].get_text() will give me "C". I will get those answers whether I choose A and then C or vice-versa. I just want to know what I just selected regardless of any previous selections. I'm capturing the ClientEvents-SelectionChanged event which appears to be the event that is fired when a user selects something from the WebDropDown control. The reason I need this is because one of the items in my dropdown is exclusive. If it is selected I want to deselect any other items.
Hi DTMartinUPS,
When selecting new item, it is added at the end of the 'eventArgs.getNewSelection()' array. So you can access the item, selected last using code similar to the following:
var lastSelectedItemIndex = eventArgs.getNewSelection().length - 1;
var lastSelectedItemText = eventArgs.getNewSelection()[lastSelectedItemIndex].get_text();
Please refer to the attached sample, replicating the scenario you have described.
If you have any questions, please feel free to contact me.
That's what I needed. Thanks.
I'm glad I could help.
Please let me know if you have any other questions.