2

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?

4

3 回答 3

5

Try this:

Dim a
Do while not rows.Eof
    a = rows.Collect("specialty")
    Response.Write("<option value=""" & Replace(a, """", "&quot;") & """>" & a & "</option>")
    rows.MoveNext
Loop
于 2013-05-24T13:01:28.183 回答
1

What is the datatype of specialty ?

try this:

    DO WHILE NOT rows.EOF
    specialty = rows("specialty")
         %>  
            <option value="<%=specialty%>"><%=specialty%></option>
         <%    
         rows.moveNext
    LOOP
于 2013-05-24T06:13:31.063 回答
0

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

于 2013-05-23T20:26:23.573 回答