Recently, I posted the question vbscript capture text in the HTML select option tag. This helped me tremendously on an Internet Explorer platform. However, I have a new project with a bit more complex of a web site. The web site has multiple nested tables that are formatted to hold form
elements. My team and I have figured out how to get and set data within most of the elements except the drop down box (select
tag). We are able to get the text from the drop down, but we can't change the value. Instead, all the options are wiped clear and the whole drop down is blank.
Here's a revised version of the code for the web site as there is much more code involved, but only the pertinent code is shown:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>...</head>
<body>
<form id="form1" action="AssignOFS.aspx" method="post">
<div class="aspNetHidden">...</div>
<div class="aspNetHidden">...</div>
<table width="100%" align="center" cellspacing="0">
<tbody>
<tr>
<td>
<table width="100%" align="center" cellspacing="0">...</table>
</td>
</tr>
<tr>
<td>
<table width="100%" align="center" cellspacing="0">
<tbody>
<tr>...</tr>
<tr>...</tr>
<tr class="tr_data">...</tr>
<tr>
<td align="center">
<div id="pnlBtn1">...</div>
<div id="pnlView">
<table width="100%" align="center" cellspacing="0">
<tbody>
<tr>...</tr>
<tr>...</tr>
<tr class="tr_data">
<td align="center">...</td>
<td valign="top">...</td>
<td valign="top">...</td>
<td valign="top">...</td>
<td nowrap="" valign="top">...</td>
<td align="left">...</td>
<td align="center">...</td>
<td align="center">
<select name="user" class="txt_input1" id="user" onchange="javascript:addUser(227);">
<option value="">--Select User--</option>
<option value="0123">Amy Jones (000456321)</option>
<option value="0432">Brian Wyatt (000745632)</option>
<option value="0345">Carl Lister (000874563)</option>
<option value="0654">Daniel Michaels (000987456)</option>
<option value="0567">Elizabeth Sweeny (001456321)</option>
<option value="0876">Fran Tarris (001745632)</option>
<option value="0789">Gail McMurphy (001874563)</option>
<option value="1098">Hannah Barisce (001987456)</option>
</select>
</td>
</tr>
</tbody>
</table
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
To be able to get the text from the drop down, we used the class
name txt_input1
after locating the node within the table that holds the drop down. This code will give us the entire list within the drop down:
objIE.Document.getElementsByTagName("table")(0).getElementsByTagName("td").Item(64).GetElementsByClassName("txt_input1")(0).innerText
I've tried changing the value of the select
drop down from "--Select User--" to one of the names in the list with the following code:
objIE.Document.getElementsByTagName("table")(0).getElementsByTagName("td").Item(64).GetElementsByClassName("txt_input1")(0).innerText = "Carl Lister"
This resulted in the blank drop down. If I changed the ending to .Value
, it only removes "--Select User--" from being shown. It still doesn't change the value to "Carl Lister". Is there something we're missing when it comes to selecting an option
in a select
drop down within nested tables?