Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling options in a drop-down box

Status
Not open for further replies.

Torp23

Programmer
Jun 13, 2002
32
0
0
US
I am trying to fill a combo (drop-down) box based on a XML 'data island' in my ASP page. All the examples that I find use an XML format where all the fields of the record are seperate elements in the data island, but I am pulling this recordset from SQL2000 with the "...FOR XML" suffix statement which creates an element for each record and all the fields are attributes of the element. Using this data-island I am able to fill a table with the data on the page, but now I need to use that same data island to fill a combo box's option list. I can't find any example or documentation that addresses this. The code I am trying is based off a purely elemental example and is not working.

Here is a sample of my XML recordset:

<root>
<pd_peopleview ID=&quot;1&quot; lname=&quot;Smith&quot;/>
<pd_peopleview ID=&quot;2&quot; lname=&quot;Jones&quot;/>
...
</root>

I think what I need is a way to scroll through all the nodes and pull out the attribute values. Any ideas on how I can fill the combo box on my asp page?
 
You can either loop through the nodes or apply an XSLT. To loop through the nodes try the following:

Code:
for each objElement in xmlDOM.documentElement.childnodes()

  response.write &quot;<option value='&quot;
  response.write objElement.getAttribute(&quot;ID&quot;)
  response.write &quot;'>&quot;
  response.write objElement.getAttribute(&quot;lname&quot;)
  response.write &quot;</option>&quot;

next

This sample assumes that you have loaded the XML into a newly created MSXML3.DOMDocument object.

If you want the XSLT approach I can post that.

James :) James Culshaw
james@miniaturereview.co.uk
 
I GOT IT!!!! :)
Here is the final script that worked... I used part of your suggestion and filled in the 'blanks':

<script language=&quot;VBscript&quot;>
function fillMgrCombo()

Dim xmldoc, nodes, N, s, stateCode, anID, aName, aList, i
set xmldom = document.all(&quot;xmlDSO&quot;)

set nodes = xmldom.selectNodes(&quot;root/pd_peopleview&quot;)
set aList = document.all(&quot;vDeptMgr&quot;)
aList.Options.length = 0
i=0

for each objElement in nodes
anID = objElement.getAttribute(&quot;ID&quot;)
aName = objElement.getAttribute(&quot;lname&quot;) & &quot;, &quot; & objElement.getAttribute(&quot;fname&quot;) & &quot; &quot; & objElement.getAttribute(&quot;MI&quot;)
aList.options.length = aList.options.length + 1
aList.options(i).id = anID
aList.options(i).value = aName
aList.options(i).innerText = aName
i=i+1
next
End Function
</script>

Thank you for your help!

PS. Could you send me the XSL post to change this XML format anyway? I would just like to learn it in case I need it in the future... thanks! :)

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top