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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<SELECT> Combo Box population 1

Status
Not open for further replies.

TudorSmith

Programmer
Jan 14, 2002
245
GB
Hi

I am creating a page to allow "Edit Details"

When the page opens, I retrieve the record details from the table...one of which is an ID reference called SiteID

When the page loads, it displays the Site Details in a <SELECT> combo box (There are 6 sites to choose from)

Everything is working fine, but what I want is for the Combo Box to automatically be selected on the value of the record I am retrieving.

So, if I retrieve the recordset and the SiteID = 3 (London) and the List of possible options is: "Bristol", "Edinburgh", "London", "Glasgow", "Liverpool" then at the moment the user sees "Bristol" in the combo box, but this is wrong, because the record for the retrived value should be "London"

Is there a way to populate the <SELECT> list first, then make it display the actual value for the record I'm retrieving?

Thanks

Tudor

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
Here is my code:

Code:
<%Dim strSiteName
  strSiteName = ilookup(objconn, "SiteName", "tblSite","SiteID = " & rst("SiteID"))%>

<TD><select name="SELECTSite" style="width: 200px;" onChange="NewValue()">
<% Dim rstSite
   Set rstSite = objConn.Execute("SELECT SiteName FROM tblSite ORDER BY 1 ASC")
   Do Until rstSite.EOF %>
      <option value="<%=rstSite("SiteName")%>"><%=rstSite("SiteName")%></option>
   <%  rstSite.movenext
   Loop
   rstSite.close%>
</select></TD>

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
You can use the 'Selected' attrbute on the option tag to preselect i.e.

<select>
<option>Bristol</option>
<option>Edinburgh</option>
<option selected>London</option>
<option>Glasgow</option>
<option>Liverpool</option>
</select>

This would preselect london for you.

You would have to change your code to pick up the selected site and check if the site from the table matches the selected.


--------------------------------
Codito, ergo sum
 
Add the changes in red below. Simply creating a variable which increments as each <OPTION> is added enables you to compare that variable with the value of your SiteID variable.

Code:
<%Dim strSiteName
  strSiteName = ilookup(objconn, "SiteName", "tblSite","SiteID = " & rst("SiteID"))%>

<TD><select name="SELECTSite" style="width: 200px;" onChange="NewValue()">
<% Dim rstSite[COLOR=red], intSelSite[/color]
   Set rstSite = objConn.Execute("SELECT SiteName FROM tblSite ORDER BY 1 ASC")
[COLOR=red]   set intSelSite = 1[/color]
   Do Until rstSite.EOF %>
      <option value="<%=rstSite("SiteName")%>"><%=rstSite("SiteName")
[COLOR=red]if intSelSite = SiteID then response.write " selected"[/color]
%></option>
   <%  rstSite.movenext
[COLOR=red]   intSelSite = intSelSite + 1[/color]
   Loop
   rstSite.close%>
</select></TD>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top