Solved

Classic ASP read selected option value

Posted on 2014-01-20
3
888 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

728 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