PDA

Click to See Complete Forum and Search --> : passing a value to a pulldown menu in ASP


vbuser1976
Mar 15th, 2001, 08:38 AM
Greetings to all my forum buddies!

I know this is a newbie question, but I don't know how to do this in vbscript.

I have a pulldown menu in an edit form. The form calls a recordset and puts the records in their corresponding boxes. I want the pulldown menu, when passed the value, to default to that value. How do I do that with out losing the options in the pull down.

I hope this doesn't sound confusing. Thanks in advance.

chrisgaddy
Mar 15th, 2001, 07:29 PM
Are the values in your pulldown box coming from a recordset also? Basically, you want to make the value from the recordset selected. Like this:

<option value="1" selected>Option 1</option>

Active
Mar 15th, 2001, 09:05 PM
See this If it helps....

<%
Dim Rating(3),RatingID

'.... Database code ......
'RatingID has a value from the database
'Say the Possible values are 0,1,2,3
'.........................

Rating(RatingID)= "Selected "

%>

<form>
<select name=Ratings>
<option value=0 <%=Rating(0)%>>Poor</option>
<option value=1 <%=Rating(1)%>>Fair</option>
<option value=2 <%=Rating(2)%>>Good</option>
<option value=3 <%=Rating(3)%>>Excellent</option>
</Select>
</form>

vbuser1976
Mar 16th, 2001, 07:03 AM
Originally posted by chrisgaddy
Are the values in your pulldown box coming from a recordset also? Basically, you want to make the value from the recordset selected. Like this:

<option value="1" selected>Option 1</option>

The values of the pull-down box are not coming from the recordset, but what you said is basically what I want to do. Lemme explain: the pulldown box has selections of 5 values(1 to 5). When they select one and save, a copy of the selected value goes to the recordset. When they want to edit that recordset, I want the value that is being returned to become the default selected. Then, if they need to, they can change it. Therefore, from what you said above, yes I want to make the value from the recordset selected.

Thanks chrisgaddy and Active for all your input.

chrisgaddy
Mar 16th, 2001, 07:44 AM
Ok, there's probably 50 ways to do this, and I don't think there's a right or wrong way. There may be a faster way(my favorite), but here's one way:

rs.Open "SELECT * FROM sometable",con,....

Select Case rs("fieldValue")
Case 1
strOptions = "<option value='1' selected>Option1 </option>"
strOptions = strOptions & "<option value='2'>Option 2</option>"

Case 2
strOptions = "<option value='1'>Option 1</option>"
strOptions = strOptions & "<option value='2' selected>Option 2</option>"

and so on and so on....

Now in your html code it should look like this:

<select name="someName"><%=strOptions%></select>

Hope that helps.

vbuser1976
Mar 16th, 2001, 08:40 AM
That was what I was looking for.

Enjoy your weekend!