Click to See Complete Forum and Search --> : Javascript & XML


mili
05-09-2003, 07:02 PM
I have an XML JS related Question.

I have a JScript that generates dropdown box like this-

td2.innerHTML = "<select size=1 name='"+name+"' id='"+name+"'><option selected>Select a Type<option value=1>String<option value=2>Float<option value=3>Integer</select>";

I dont want to hardcode the option values within the JS.I need to be able to extract these values from an XML document.How can I do this

My XML structure is something like this:

<options>
<option value="1">string</string>
<option value="2">Integer</string>
<option value="3">Float</string>
</options>

Thanks,

sheila
05-10-2003, 08:43 AM
If you intend to use XSLT, I think this should work, although you would need to add another element to your XML containing the name of the option menu:

<xsl:template match="options">
<select size="1" name="{name}" id="{name}">
<option selected>
<xsl:for-each select="option">
<option value="{@value}"><xsl:value-of select="." /></option>
</xsl:for-each>
</select>
</xsl:template>