Forum Moderators: coopster & phranque

Message Too Old, No Replies

Selected item in a drop down box

VBScript

         

Big_Perm

5:09 pm on Aug 3, 2001 (gmt 0)



After my drop down box is submitted in a form, i bring up values according to the selection in the drop down box, but i also need the value that was just selected to be the selected value in the box after submission. I am using the code below to get the options in the drop down box from a database. The problem is that the If statement never returns true, even if I print the values for objRS1(0) and strTemp1 and they are the same. I'm clueless why the if statement won't return true. Please Help...

While Not objRS1.EOF
Response.Write ("<option")
If (objRS1(0) = strTemp1) Then
Response.Write (" selected")
End If
Response.Write (" value=" & objRS1(0) & ">" & objRS1(1) & "</option>")
objRS1.MoveNext
Wend

circuitjump

5:45 pm on Aug 3, 2001 (gmt 0)

10+ Year Member



I think the problem might be the ( and )

Try it like this

While Not objRS1.EOF
Response.Write ("<option")
If objRS1(0) = strTemp1 Then
Response.Write (" selected")
End If
Response.Write (" value=" & objRS1(0) & ">" & objRS1(1) & "</option>")
objRS1.MoveNext
Wend

Do you have a link I can take a look at?

Big_Perm

5:50 pm on Aug 3, 2001 (gmt 0)



I don't have a link because it is on an intranet, but here's more code:<select size="1" name="sortPlant" style="color: #800000; font-family: Arial; font-size: 10pt">

<%
'Response.Write("<option value=all>All Plants</option>")

Set objRS1 = Server.CreateObject("ADODB.Recordset")
Set objRS1.ActiveConnection = objConn

strQ = "SELECT Plants.ID, Plants.Description FROM Plants;"
objRS1.Open strQ

While Not objRS1.EOF
Response.Write ("<option")
If (objRS1(0) = strTemp1) Then
Response.Write (" selected")
End If
Response.Write (" value=" & objRS1(0) & ">" & objRS1(1) & "</option>")
objRS1.MoveNext
Wend

objRS1.Close
Set objRS1 = Nothing
%>
  </select><br>

Big_Perm

5:53 pm on Aug 3, 2001 (gmt 0)



I tried removing the parenthesis but it still didn't work

circuitjump

6:19 pm on Aug 3, 2001 (gmt 0)

10+ Year Member



Try this and see what happens.

<%
'Response.Write("<option value=all>All Plants</option>")

Set objRS1 = Server.CreateObject("ADODB.Recordset")
Set objRS1.ActiveConnection = objConn

' Here you give the SQL command
strQ = "SELECT * FROM users;"
objRS1.Open strQ
' Here you execute the SQL command
Set rs = con.Execute (strQ)

' Here is your WHILE Loop
While Not objRS1.EOF
Response.Write ("<option")

' Here we have your IF statement
If (objRS1(0) = strTemp1) Then
Response.Write (" selected")
End If

Response.Write (" value=" & objRS1(0) & ">" & objRS1(1) & "</option>")
objRS1.MoveNext
Wend

objRS1.Close
Set objRS1 = Nothing
%>

I think what it is, is that you did not execute the SQL command. Also, are you doing an array variable with objRS1(0)?

Big_Perm

6:32 pm on Aug 3, 2001 (gmt 0)



I am not using an array, but the recordset changes using objRS1.MoveNext. If i print objRS1(0) and strTemp1, they print exactly right: there is always one and only one instance where they are the same, so my only guess is that the data type of strTemp1 is wrong, but i'm not sure how to specify a data type.

circuitjump

6:42 pm on Aug 3, 2001 (gmt 0)

10+ Year Member



I'm sorry, I've run out of ideas. I'm also fairly new to ASP and am more into PHP, but can still handle my own on both. If I see something that can help I'll make sure to post it. I'll keep looking at the code. In fact what I'll do is try and see if I can do it your way. Maybe by seeing the script run I can get a better idea.

Big_Perm

6:44 pm on Aug 3, 2001 (gmt 0)



Thanks for your help, I appreciate it. I am fairly experienced with ASP and am truly dumbfounded by this.