Solved

Classic ASP read selected option value

Posted on 2014-01-20
3
893 Views
Last Modified: 2014-01-26
The below code always returns the first option value, but I need it to return the selected value.
What am I missing.
This runs in a classic asp page.


set html = CreateObject("htmlfile")
                  html.write InstanceXMLFetchA_R.selectsinglenode("//scrunner[@SeqNo='1']/srcontent").textset termdetail = html.getElementById("termDetail")

 'html is some html content like this
<SELECT class=dtMM><OPTION value=1>1</OPTION><OPTION value=2>2</OPTION><OPTION value=3>3</OPTION><OPTION selected value=4>4</OPTION><OPTION value=5>5</OPTION><OPTION value=6>6</OPTION><OPTION value=7>7</OPTION><OPTION value=8>8</OPTION><OPTION value=9>9</OPTION><OPTION value=10>10</OPTION><OPTION value=11>11</OPTION><OPTION value=12>12</OPTION></SELECT> <SELECT class=dtDD><OPTION value=1>1</OPTION><OPTION value=2>2</OPTION><OPTION value=3>3</OPTION><OPTION value=4>4</OPTION><OPTION value=5>5</OPTION><OPTION value=6>6</OPTION><OPTION value=7>7</OPTION><OPTION value=8>8</OPTION><OPTION value=9>9</OPTION><OPTION value=10>10</OPTION><OPTION value=11>11</OPTION><OPTION value=12>12</OPTION><OPTION value=13>13</OPTION><OPTION value=14>14</OPTION><OPTION value=15>15</OPTION><OPTION value=16>16</OPTION><OPTION value=17>17</OPTION><OPTION value=18>18</OPTION><OPTION value=19>19</OPTION><OPTION value=20>20</OPTION><OPTION value=21>21</OPTION><OPTION value=22>22</OPTION><OPTION value=23>23</OPTION><OPTION selected value=24>24</OPTION><OPTION value=25>25</OPTION><OPTION value=26>26</OPTION><OPTION value=27>27</OPTION><OPTION value=28>28</OPTION><OPTION value=29>29</OPTION><OPTION value=30>30</OPTION><OPTION value=31>31</OPTION></SELECT> <SELECT class=dtYYYY><OPTION selected value=2013>2013</OPTION><OPTION value=2014>2014</OPTION></SELECT></TD>

termdetail.getElementsByTagName("tr")(0).getElementsByTagName("td")(1).getElementsByTagName("select")(0).getElementsByTagName("option")(selectedIndex).value
0
Comment
Question by:KeithMcElroy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39794634
what is this line supposed to do?

termdetail.getElementsByTagName("tr")(0).getElementsByTagName("td")(1).getElementsByTagName("select")(0).getElementsByTagName("option")(selectedIndex).value

which item do you want to be selected?
0
 

Author Comment

by:KeithMcElroy
ID: 39794934
I just need to retreive the selected option into a local variable, so end game will be something like.

dim selval
selval = termdetail.getElementsByTagName("tr")(0).getElementsByTagName("td")(1).getElementsByTagName("select")(0).getElementsByTagName("option")(selectedIndex).value
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 39794950
do you have the option to give the select box an ID or NAME attribute? if so, you would do:

var selVal = document.getElementById('selectBoxID').options[ document.getElementById('selectBoxID').selectedIndex ].value;

when you say "local variable", I assume you meant after the user selected an item. You would need to use javascript to retrieve it, which I provided an example for
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question