Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing an Id to the drop down list.

Status
Not open for further replies.

haneen97

Programmer
Dec 10, 2002
280
US
Hi,
I have the dropdown box below. The array loads the list for possible selections. But, as the user views existing products, I would like to view the saved product type. Right now it is stock on the first type in the list. I tried to use that value='<%=PType%>', which it has the saved product type, but it is not working.



<select name="lstType" value='<%=PType%>' size="1" id="lstType" >>
<%
for j = tFirstRec to tLastRec
%>
<option value='<%= TypesArray(0,j)%>'><%= TypesArray(1,j)%></option>
<%
next
%>
</select>

Please advise.

Thanks

Mo
 
I don't understand the question.

Does the user pick one <option> and then submit the form in order to view a product?

Or maybe you just want the <option> in PType to be the one that is selected when the page loads?

If it is the latter then something like this could help:
Code:
<%
    for j = tFirstRec to tLastRec
%>
            <option value='<%= TypesArray(0,j)%>' [red]<% IF TypesArray(0,j) = PType THEN Response.Write " selected " %>[/red]><%= TypesArray(1,j)%></option>
<%
    next
%>
 
Yes,
I want the <option> in PType to be the one that is selected when the page loads.

But the code above collected all the types and displayed them. I would like to display the one that is in PType.

In another word. I would like all the list available just in case they are adding a new product. But if they are editing an existing product, I want to load the attached type.

Mo
 
so try

Code:
<%
    for j = tFirstRec to tLastRec
%>
            <option value='<%= TypesArray(0,j)%>' <% IF clng(TypesArray(0,j)) = clng(PType) THEN Response.Write " selected " %>><%= TypesArray(1,j)%></option>
<%
    next
%>
 
So depending on how the page is loaded, the behavior will either be (A) show the full dropdown list or (B) show only the selected <option> ??

To show only the one selected option you could re-arrange the code above like this:
Code:
<%
    for j = tFirstRec to tLastRec
      IF TypesArray(0,j) = PType THEN 
%>
 <option value='<%= TypesArray(0,j)%>' selected><%= TypesArray(1,j)%></option>
<%
         Exit For
      END IF
    next
%>
 
Oh, disregard the last thing I posted. I misunderstood the problem with the first code.
 
Yes, thanks to both of you. It is working great.

Mo

Mo
 
Yes, thanks to both of you. It is working great.



Mo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top