Hi,
I am using webdropdown version: 11.2.20112.1019. I would like to retrieve value and lenght of the dropdown item(s) based upon ID and do some valildations in javascript. Can you tell me the syntax of retrieving value and length from this dropdown field.
Hi SunilMehta,
I was not sure if you need the length of the items collection, or the length of the current item (as a number of the characters it contains), so I've provided both samples.
Here is code that take an instance of the WebDropDown, by ID. Keep in mind that if you use master pages and your control is in content place holder its id get changed when rendered, so you need to use a debugger to find its id and pass it as an argument to the find function. If you are using ASP.NET 4 you can also set ClientIDMode="Static", which won't change the value of the id.
19 function clickHandler() {
20 //Get instance of the webdropdown
21 var dd = $find("WebDropDown1");
22 //Get the length of the items collection
23 var length = dd.get_items().getLength();
24 //Get item with index 0
25 var item = dd.get_items().getItem(0);
26 //Get the text of the item
27 var textValue = item.get_text();
28 //Get the string length
29 var stringLength = textValue.length;
30 }
Hope that helps,
Thanks
Thanks for your reply. I am actually using document.all in my javascript file to check the value of an item. For example, if the ID of webdropdown is "ABC" and the current value selected in the dropdown is "1234", then the check is like that:
if(document.all.ABC.popup.value == "1234")
This statement is not working in your webdropdown. I am looking for something where i can reuse the existing statement with some minor changes.
Thanks for the documentation.
I am facing an issue while retrieving the value from the dropdown. The problem is:
For instance, I have two values in the dropdown:
0100 TEST
0200 SAMPLE
and "0200 SAMPLE" is the current selected value.
When I use
i) $find(
"webdropdownID").get_currentValue(), it gives me "0200 SAMPLE".
ii) $find("webdropdownID").get_items().getItem(1).get_value(), it gives only "0200".
Is there a way that I can retrieve "0200" with option 1 instead of "0200 SAMPLE"?
Here is extension of the code snippet I gave on the first post:
.....
30 //Get selected item
31 var selectedItem = dd.get_selectedItem();
32 //Get selected item's text
33 var selectedItemText = dd.get_selectedItem().get_text();
Thanks,
Thanks for your quick response. I have tried the code snippets you mentioned but still I am not able to see "0200".
i) var x = $find("webdropdownID").get_selectedItem();
alert(
'x:' + x);
Output: Object Object
The above output is not expected.
ii) var y = $find("webdropdownID").get_selectedItem().get_text();
'y:' + y)
Output: 0200 SAMPLE
In addition to the above query,
Can you please let me know the code snippets for the following as well:
i) How to retrieve the number of elements from a webdropdown?
ii) How to check if a webdropdown is filled with some value or not??
Sorry, posted by accident will inlcude the second part into a second post. The following are already answered, but I will point you to the answer:
24 if (length == 0) {
25 //The WebDropDown has no value into it
26 } else {
27 //The WebDropDown has value into it
28 }
Yes once you have static clientID you can use getElementById.
I change this property in the object
ClientIDMode="Static"
and then I use in javascrip
document.getElementById
Hello SunilMehta,
It appears that your question has been discussed at:
http://es.infragistics.com/community/forums/t/70709.aspx?PageIndex=1
Please do not hesitate to contact me if you have any further questions regarding this scenario.
We are facing the above issue from a long time. We need to see how the trial version of the webdropdown behaves with our application. Based upon that, we will be trying for a paid license of this control. I am explaining the issue once again below:
var sample = $find("webdropdown");
I get "null" in "sample" variable. It was working fine 15 days ago. Do you know anything about this issue?
I will be really thankful if i get a reply soon.