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

SELECT box from database

Status
Not open for further replies.

Ouch

Programmer
Jul 17, 2001
159
GB
does anyone know how i can get a select box to default to a value from a database?

a webpage opens and fills itself in from a record on a database, but i need the option to change the infomation


<%=rscourse(&quot;ctemplate&quot;)%> will = either SCT, photo_basic, photo or photo_comprehensive


<SELECT NAME=&quot;default_template&quot; ONCHANGE=&quot;doSelectChange_template()&quot; STYLE=&quot;position:static;width:264;overflow:visible;font:smaller&quot;
<OPTION VALUE=&quot;SCT&quot; SELECTED>Simple
<OPTION VALUE=&quot;photo_basic&quot;>Basic
<OPTION VALUE=&quot;photo&quot;>Intermediate
<OPTION VALUE=&quot;photo_comprehensive&quot;>Advanced
</SELECT> </font>

Can anyone help me?
 
Here is a vbscript sub to do the trick.
The arguments are the control: (default_template)
and the Value or what you want selected.


sub SetOptionIndex(oFld, sValue)
dim bFound

bFound = false
for x = 0 to oFld.length - 1
if oFld.options(x).value = sValue or oFld.options(x).text = sValue then
oFld.selectedindex = x
bFound = true
exit for
end if
next
if not bFound then oFld.selectedindex = -1

end sub
 
how would i impliment this? where would i fire the event

i have to do it on for or five controls

oFld = &quot;default_template&quot;
sValue = <%=rscourse(&quot;ctemplate&quot;)%>

<SELECT NAME=&quot;default_template&quot; ONCHANGE=&quot;doSelectChange_template()&quot;
<OPTION VALUE=&quot;SCT&quot; SELECTED>Simple
<OPTION VALUE=&quot;photo_basic&quot;>Basic
<OPTION VALUE=&quot;photo&quot;>Intermediate
<OPTION VALUE=&quot;photo_comprehensive&quot;>Advanced
</SELECT> </font>
 
You could do it this way. Write out a script block to call the SetOptionIndex. This will run when the page loads.

response.write &quot;<script language=vbscript>&quot;
response.write &quot;SetOptionIndex( &quot;default_template&quot;,rscourse(&quot;ctemplate&quot;))
response.write &quot;</script>


Other wise you could do it server side.

<SELECT NAME=&quot;default_template&quot; ONCHANGE=&quot;doSelectChange_template()&quot;
<OPTION VALUE=&quot;SCT&quot; <% if rscourse(&quot;ctemplate&quot;)= &quot;SCT&quot; Then &quot;SELECTED&quot; end if %> >Simple</OPTION>
<OPTION VALUE=&quot;photo_basic&quot; <% if rscourse(&quot;ctemplate&quot;)= &quot;photo_basic&quot; Then &quot;SELECTED&quot; end if %>>Basic</OPTION>
<OPTION VALUE=&quot;photo&quot; <% if rscourse(&quot;ctemplate&quot;)= &quot;photo&quot; Then &quot;SELECTED&quot; end if %>>Intermediate</OPTION>
<OPTION VALUE=&quot;photo_comprehensive&quot; <% if rscourse(&quot;ctemplate&quot;)= &quot;photo_comprehensive&quot; Then &quot;SELECTED&quot; end if %>>Advanced</OPTION>
</SELECT> </font>
 
Sorry to be a pain..

i just get a error when i try to run the script block
cannot use parethesis when calling a sub&quot;

i tryed this and its close, but it write selected in the lised nest to the correct value

<SELECT NAME=&quot;default_template&quot; ONCHANGE=&quot;doSelectChange_template()&quot; STYLE=&quot;position:static;width:264;overflow:visible;font:smaller&quot;>
<option>&lt;&lt;Select template&gt;&gt;</option>
<% Do While Not rstemplate.EOF %>
<option value=&quot;<% = rstemplate(&quot;template_id&quot;)%>&quot;>
<% if rscourse(&quot;ctemplate&quot;)= rstemplate(&quot;template_id&quot;) Then response.write(&quot;SELECTED&quot;) end if %><% = rstemplate(&quot;template&quot;) %>
</option>
<% rstemplate.movenext %>
<% loop %>
</SELECT>
<% rstemplate.movenext %>
<% loop %>
</SELECT> </font> </TD>
 
not a problem

when you do the response.write remove the parethesis.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top