sparkyrocks
Programmer
I am retrieving data from a database and creating an
XML file which is valid and well formed. When I run my
.asp page I am attempting to fill a select box with
the data contained in the xml file as follows
1. A client side VBScript sub routine is fired when
the <BODY ONLOAD = "FillCombo">
2. I create the object and load the xml file as
follows
Set doc = CreateObject("Microsoft.XMLDOM"
doc.async = False
doc.load "XML/coopdata.xml"
3. The xml file contains these nodes which I want to
use to populate a select box:
<code>CLS</code>
<code>YP</code>
<codePRT</code>
<code>OTH</code>
So I get these values by
Set codes = doc.getElementsByTagName("code"
To determine if I am retrieving the data I perform
this test in my script by looping thru the collection
For Each code in codes
str = str & code.firstChild.nodeValue & vbCrlf
Next
MsgBox str
The message box contains all the values so at this
point everything is hunky dory. The problem is when I
try to dynamically attempt to assign these values to
an empty select box with the following
i=0
For Each code in codes
document.frmAddClaim.cboMediaType.options(i).value =
code.firstChild.nodeValue
i = i+1
Next
I get this error
Error:Object required
document.frmAddClaim.cboMediaType.options(...)
I believe this error message is telling me that
select.option(0) does not exist. So in my next test I
hard coded one value in the select box
<option value = "Test">
Test
</option>
Then I adjusted my loop to dynamically assign the
value from the collection to the 1 and only <option>
in the select box
For Each code in codes
document.frmAddClaim.cboMediaType.options (0).value =
code.firstChild.nodeValue
document.frmAddClaim.cboMediaType.options(0).text =
code.firstChild.nodeValue
Next
And it worked. So what this is telling me is that
client side script can only assign values to <option>
tags that already exist. I do not know how to create
client side script that creates the <option> tags
dynamically for the select box so I can populate them
with values from the codes collection.
So then I decided to attempt server side script (which
is my background). Typically I would grab data from a
recordset and loop thru it to create all the <option>
tags for the select box. This is the snippet of server
side code
Set doc = Server.CreateObject("Microsoft.XMLDOM"
doc.async = False
doc.load "XML/coopdata.xml"
Set codes = doc.getElementsByTagName("code"
For Each code in codes
str = str & code.firstChild.nodeValue & vbcrlf
Next
Response.Write str
As you can see I am attempting to pull data from my
codes collection. For some reason the variable str is
an empty string when I attempt this server side. No
.asp errors are generated. So then I changed the code
to
doc.load "XML/coopda.xml"
I figured this would generate an error since no such
file exists. No error was returned. So then I changed
the code so the load method would accept a full path
doc.load "C:\Bruce\Coop Advertising\Web
Application\XML\coopdata.xml"
Still no data from the collection.
To summarize my dilemna is the following
1. When I run client side script I can use DOM to
retrieve the data but I have no idea how to get the
data into a select box.
2. When I run server side script I cannot retrieve the
data but I know how to get data into a select box.
Can someone help? Any assistance would
be greatly appreciated.
XML file which is valid and well formed. When I run my
.asp page I am attempting to fill a select box with
the data contained in the xml file as follows
1. A client side VBScript sub routine is fired when
the <BODY ONLOAD = "FillCombo">
2. I create the object and load the xml file as
follows
Set doc = CreateObject("Microsoft.XMLDOM"
doc.async = False
doc.load "XML/coopdata.xml"
3. The xml file contains these nodes which I want to
use to populate a select box:
<code>CLS</code>
<code>YP</code>
<codePRT</code>
<code>OTH</code>
So I get these values by
Set codes = doc.getElementsByTagName("code"
To determine if I am retrieving the data I perform
this test in my script by looping thru the collection
For Each code in codes
str = str & code.firstChild.nodeValue & vbCrlf
Next
MsgBox str
The message box contains all the values so at this
point everything is hunky dory. The problem is when I
try to dynamically attempt to assign these values to
an empty select box with the following
i=0
For Each code in codes
document.frmAddClaim.cboMediaType.options(i).value =
code.firstChild.nodeValue
i = i+1
Next
I get this error
Error:Object required
document.frmAddClaim.cboMediaType.options(...)
I believe this error message is telling me that
select.option(0) does not exist. So in my next test I
hard coded one value in the select box
<option value = "Test">
Test
</option>
Then I adjusted my loop to dynamically assign the
value from the collection to the 1 and only <option>
in the select box
For Each code in codes
document.frmAddClaim.cboMediaType.options (0).value =
code.firstChild.nodeValue
document.frmAddClaim.cboMediaType.options(0).text =
code.firstChild.nodeValue
Next
And it worked. So what this is telling me is that
client side script can only assign values to <option>
tags that already exist. I do not know how to create
client side script that creates the <option> tags
dynamically for the select box so I can populate them
with values from the codes collection.
So then I decided to attempt server side script (which
is my background). Typically I would grab data from a
recordset and loop thru it to create all the <option>
tags for the select box. This is the snippet of server
side code
Set doc = Server.CreateObject("Microsoft.XMLDOM"
doc.async = False
doc.load "XML/coopdata.xml"
Set codes = doc.getElementsByTagName("code"
For Each code in codes
str = str & code.firstChild.nodeValue & vbcrlf
Next
Response.Write str
As you can see I am attempting to pull data from my
codes collection. For some reason the variable str is
an empty string when I attempt this server side. No
.asp errors are generated. So then I changed the code
to
doc.load "XML/coopda.xml"
I figured this would generate an error since no such
file exists. No error was returned. So then I changed
the code so the load method would accept a full path
doc.load "C:\Bruce\Coop Advertising\Web
Application\XML\coopdata.xml"
Still no data from the collection.
To summarize my dilemna is the following
1. When I run client side script I can use DOM to
retrieve the data but I have no idea how to get the
data into a select box.
2. When I run server side script I cannot retrieve the
data but I know how to get data into a select box.
Can someone help? Any assistance would
be greatly appreciated.