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. General Programming
  3. Visual Basic
  4. dropdown item access thro' Javascript

dropdown item access thro' Javascript

Scheduled Pinned Locked Moved Visual Basic
databasequestioncsharpjavascript
2 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.
  • A Offline
    A Offline
    anarayan
    wrote on last edited by
    #1

    I have a web control which is a dropdown list box (created & populated in VB.NET) - I want to be able to manipulate the selected value of this dropdown box based on text entered elsewhere (in another control - a textbox). For this I'd like to use the onkeyup or onkeypress methods and trigger a Javascript function which will select a particular value in the dropdown box. My dropdown box is not a typical HTML options box, but it's a VB dropdown web control. Such being the case how do I do this in Javascript? I found some code elsewhere (which I'm listing below) but this will not apply (I think) in my case - do I use some other getElement* method to get to the first item populated in the dropdown box? function searchDropdown(searchStr,ddObj) { var index = ddObj.getElementsByTagName("option"); for(var i = 0; i < index.length; i++) { if(index[i].firstChild.nodeValue.toLowerCase().substring(0,searchStr.length) == searchStr.toLowerCase()) { index[i].selected = true; break; } } }

    C 1 Reply Last reply
    0
    • A anarayan

      I have a web control which is a dropdown list box (created & populated in VB.NET) - I want to be able to manipulate the selected value of this dropdown box based on text entered elsewhere (in another control - a textbox). For this I'd like to use the onkeyup or onkeypress methods and trigger a Javascript function which will select a particular value in the dropdown box. My dropdown box is not a typical HTML options box, but it's a VB dropdown web control. Such being the case how do I do this in Javascript? I found some code elsewhere (which I'm listing below) but this will not apply (I think) in my case - do I use some other getElement* method to get to the first item populated in the dropdown box? function searchDropdown(searchStr,ddObj) { var index = ddObj.getElementsByTagName("option"); for(var i = 0; i < index.length; i++) { if(index[i].firstChild.nodeValue.toLowerCase().substring(0,searchStr.length) == searchStr.toLowerCase()) { index[i].selected = true; break; } } }

      C Offline
      C Offline
      CWIZO
      wrote on last edited by
      #2

      That code is really ugly... It is designed to go trough all the options in all the selectobxes on the form. But when it finds the first item that match it breaks from searching leaving other potential mathing options (in other selectboxes) un-selected. What you should do is write a function that will take two arguments. One is search string, and the other is the ID of your select box. This function should only go trough the options of that selectbox. Then you simply add the onkeydown event and call your function from there. -------------------------------------------------------- Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

      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