Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How can I get an attribute of a DropDownList item using javascript?

How can I get an attribute of a DropDownList item using javascript?

Scheduled Pinned Locked Moved ASP.NET
questionjavascript
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martin_
    wrote on last edited by
    #1

    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.

    K 1 Reply Last reply
    0
    • M Martin_

      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.

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      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

      M 2 Replies Last reply
      0
      • K kubben

        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

        M Offline
        M Offline
        Martin_
        wrote on last edited by
        #3

        This also worked var index =document.getElementById("cbBudget").selectedIndex; alert(document.getElementById("cbBudget").options[index].bLocked) Thanks Ben

        1 Reply Last reply
        0
        • K kubben

          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

          M Offline
          M Offline
          Martin_
          wrote on last edited by
          #4

          Thanks Ben, That is a great article, now I don't have to Alert("I am here"); anymore. Martin

          K 1 Reply Last reply
          0
          • M Martin_

            Thanks Ben, That is a great article, now I don't have to Alert("I am here"); anymore. Martin

            K Offline
            K Offline
            kubben
            wrote on last edited by
            #5

            Glad you liked it. Without it I don't think I would have gotten into javascript. Too much like the old Cobol programming I used to have to do with the "I am here" to debug. Ben

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups