How can I get an attribute of a DropDownList item using javascript?
-
Hi, I added an attribute to the items of a DropDownList. cbBudget.Items(0).Attributes.Add("bLocked", true) cbBudget.Items(1).Attributes.Add("bLocked", false) Now I want to get the value of the selected item in the DropDownList using javascript. I tried something like this: document.getElementById("cbBudget").selectedItem.getAttribute("bLocked") but it doesn't work. The source looks like this: Class1 Class 2 Thank you for your suggestions.
-
Hi, I added an attribute to the items of a DropDownList. cbBudget.Items(0).Attributes.Add("bLocked", true) cbBudget.Items(1).Attributes.Add("bLocked", false) Now I want to get the value of the selected item in the DropDownList using javascript. I tried something like this: document.getElementById("cbBudget").selectedItem.getAttribute("bLocked") but it doesn't work. The source looks like this: Class1 Class 2 Thank you for your suggestions.
Something like this should work:
var ddl = document.getElementByName("cbBudget");
if (ddl != null && ddl.length > 0)
{
ddl[0].attributes["bLocked"];
}I wrote an article on debuggin javascript. That might help you: http://www.codeproject.com/useritems/UsingVSToDebugJavascript.asp[^] Hope that helps. Ben
-
Something like this should work:
var ddl = document.getElementByName("cbBudget");
if (ddl != null && ddl.length > 0)
{
ddl[0].attributes["bLocked"];
}I wrote an article on debuggin javascript. That might help you: http://www.codeproject.com/useritems/UsingVSToDebugJavascript.asp[^] Hope that helps. Ben
-
Something like this should work:
var ddl = document.getElementByName("cbBudget");
if (ddl != null && ddl.length > 0)
{
ddl[0].attributes["bLocked"];
}I wrote an article on debuggin javascript. That might help you: http://www.codeproject.com/useritems/UsingVSToDebugJavascript.asp[^] Hope that helps. Ben
-
Thanks Ben, That is a great article, now I don't have to Alert("I am here"); anymore. Martin