Missing value from variable - html

I'm trying to populate a <select> with <option>'s on a site with Classic ASP/VBScript. The values are read and taken from an SQL Server Database and the code for that looks similar to:
SET rows = dbc.execute(SQL)
IF NOT rows.EOF THEN
DO WHILE NOT rows.EOF
%>
<option value="<%=rows("specialty")%>"><%=rows("specialty")%></option>
<%
rows.moveNext
LOOP
ELSE
END IF
rows.close
SET rows = NOTHING
The problem I have is that only one side of the <%=rows("specialty")%> seems to evaluate.
With <option value="<%=rows("specialty")%>"><%=rows("specialty")%></option> I get:
<option value="fromRow1"></option>
<option value="fromRow2"></option>
<option value="fromRow3"></option>
With <option value="test"><%=rows("specialty")%></option> I get:
<option value="test">fromRow1</option>
<option value="test">fromRow2</option>
<option value="test">fromRow3</option>
What should one do to mitigate this issue?

Try this:
Dim a
Do while not rows.Eof
a = rows.Collect("specialty")
Response.Write("<option value=""" & Replace(a, """", """) & """>" & a & "</option>")
rows.MoveNext
Loop

What is the datatype of specialty ?
try this:
DO WHILE NOT rows.EOF
specialty = rows("specialty")
%>
<option value="<%=specialty%>"><%=specialty%></option>
<%
rows.moveNext
LOOP

Try this:
<option value='<%=rows("specialty")%>'><%=rows("specialty")%></option>
it might be getting confused with the doubles quotes. But it has been a while since I've worked in Classic ASP

Related

Html select multiple returns last value

I have gone through this and several other examples the code simply doesn't work when I pprint on the backend of django.
<select name="multiple-select[]" id="multiple-select" multiple>
<option value="1">Books</option>
<option value="2">Movies, Music & Games</option>
<option value="3">Electronics & Computers</option>
<option value="4">Home, Garden & Tools</option>
<option value="5">Health & Beauty</option>
<option value="6">Toys, Kids & Baby</option>
<option value="7">Clothing & Jewelry</option>
<option value="8">Sports & Outdoors</option>
</select>
When I select multiple items, the last item is what will be printed out not an array of items as expected.

Using VBA to choose from Dropdown in HTML

I am trying to use VBA to select from a dropdown list. The HTML code is below
<select name="template" class="chzn-select stdText allow_single_deselect"
id="template" style="width: 315px; display: none; visibility: visible;"
onchange="newDoc.doAfterTemplateNew('templateRow',this);" size="3"
data-automation-id="authorTemplateDropdown" data-placeholder="Choose template...">
<option></option>
<option value="1">1. Company_Comment (CC)</option>
<option value="3">1. Company_Flash (CF)</option>
<option value="79">1. Company_Report (CR)</option>
<option value="21">2. Sector_Comment (SC)</option>
Right now I am trying to use:
.document.querySelector("Select[name=template] option[value=1]").Selected = True
However, I am getting error 8070000c. Thank you for the help!
This worked for me. Note quotes around option value attribute
Sub tester()
'Added reference to Microsoft HTML Object Model
Dim doc As New HTMLDocument, opt As Object, slct As Object
doc.body.innerHTML = Range("A1").Value 'load HTML from cell for testing
Set slct = doc.querySelector("select[name=template]") 'select object
Set opt = doc.querySelector("select[name=template] option[value='1']") 'option
Debug.Print "before", slct.selectedIndex ' >> -1
opt.Selected = True
Debug.Print "after", slct.selectedIndex ' >> 1
End Sub
HTML in A1:
<select name="template" id="template" size="3" data-placeholder="Choose template...">
<option></option>
<option value="1">1. Company_Comment (CC)</option>
<option value="3">1. Company_Flash (CF)</option>
<option value="79">1. Company_Report (CR)</option>
<option value="21">2. Sector_Comment (SC)</option>
</select>

Select value from "option value" select

Hope someone can help as this is a new one on me.
I'm trying to extract the "option value" from a particular location.
E.g. in the example below, I want to get the 2.0000 from "Ashton".
The HTML is
<div class="store-stock-select">
<select name="storestock" id="storestock" onchange="showMessage()">
<option value="">Check Store Stock</option>
<option value="2.0000">Ashton</option>
<option value="1.0000">Ballymena</option>
<option value="0.0000">Banbridge</option>
<option value="2.0000">Bangor</option>
<option value="0.0000">Bedford</option>
<option value="1.0000">Belfast</option>
<option value="1.0000">Blyth</option>
<option value="0.0000">Bolton</option>
<option value="0.0000">Bridgwater</option>
<option value="1.0000">Bristol</option>
...and the VBA I've tried so far is
Set dropOptions = HTML.getElementsByTagName("select")
For Each o In dropOptions.Options
If o.innertext = "Ashton" Then sh01.Cells(r, 5) = o.Value
Next
But to no avail. :(
If anyone could help me with this I would be so very grateful.
Thank you in advance.
Ian
You can use CSS selectors
HTML.querySelector("#storestock option + option[value]").value
Also,
HTML.querySelectorAll("#storestock option").item(1).Value

Pull data from HTML dropdown

I'm looking for a way to extract data from the available options from a website dropdown box, specifically the second optgroup "All fund companies".
extract of HTML code I'm scraping
</div><div class="large-5 medium-5 columns spacer-bottom padding-left-none"><div class="select_wrap"><select id="search-company" name="companyid" class="default">
<option value="">Search by company</option>
<optgroup label="Popular companies">
<option value="4">Hargreaves Lansdown</option>
<option value="1908">Lindsell Train</option>
<option value="55">Jupiter</option>
<option value="191">Legal & General</option>
</optgroup>
<optgroup label="All fund companies">
<option value="218">Aberdeen</option>
<option value="1080">Aberforth Unit Trust Managers</option>
<option value="141">Allianz Global Investors</option>
<option value="3472">Alquity Investment Management Limited</option>
<option value="1324">Amati Global Investors Ltd</option>
VBA:
Set htmlObj = html.getElementById("search-company")
For Each Child In htmlObj.getElementByClassName("optgroup")(1).Children
sqlId = Child.Value
sqlCompany = Child.innerText
Debug.Print (sqlId & " - " & sqlCompany)
Next
Thanks Jeeped...
This is the code that managed to solve the problem... not sure if it's the most efficient way of doing it, but it works :)
Set htmlObj = html.getElementById("search-company")
For Each Child In htmlObj.Children
If Child.Label = "All fund companies" Then Set htmlObj2 = Child
Next
For Each Child In htmlObj2.Children
sqlId = Child.Value
sqlCompany = Child.innerText
Debug.Print (sqlId & " - " & sqlCompany)
Next

asp classic and select tag with multiple attribute

I am using select tag of html and having multiple attribute. and now I am fetching of selected option from the select tag using asp classic. but getting 500 internal server error.
<%
response.write(request("evtCategory").Count)
response.write(request("evtCategory"))
%>
<form id="frmSearch" method="post" >
<select name="evtCategory" multiple>
<option value="0">--Select Category--</option>
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
<option value="4">Fourth</option>
<option value="5">Fifth</option>
</select>
<input type="submit" value="Search" />
</form>
I don't think Count exists in Classic ASP, that looks like ASP.NET code.
Multiple selected values will be returned as a comma separated string.
You can use Split to get the selected values as an array.
Dim values, i
values = Split(Request.Form("evtCategory"), ",")
For i = 0 To UBound(values)
Response.Write("Value " & i & " = " & values(i) & "<br />")
Next