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

How to change text box to combo box

Status
Not open for further replies.

Spyder1000

Technical User
Nov 2, 2004
109
US
I'm new to ASP and i've just created a simple page in which I type a value into a text box, press the submit button, and the results of my query are returned.

However I'd like to change my text box to a combo box so that I may enter some values for my users to select frmo.

Any suggestions?
 
Something like this:
Code:
<form method="POST" action="blah.asp">
<p><small><font face="Arial">Values: </font></small>
<select name="group" size="1">
<option value="1">"-Select One-"</option>
<option value="2">"Value2"</option>
<option value="3">"Value3"</option>
<option value="4">"Value4"</option>
</select>
<input type="submit" value="Submit" name="B1"></p>
</form>

but if you want to pull the values from the database instead of writing them manually then do something like this

Code:
<form method="POST" action="blah.asp">
<p><small><font face="Arial">Values: </font></small>
<select name="group" size="1">
<option value="-Select One-">-Select One-</option>
<%while NOT rs.EOF%> 
<option value="<%=rs("recno")%>"><%=rs("group")%></option>
<%rs.MoveNext
wend
rs.Close%> 
</select>
<input type="submit" value="Submit" name="B1"></p>
</form>

-L

 
Thank you for your help. I got your first example to work perfectly. I had a bit of trouble with your 2nd example.

My table is called "Tbl_MainTable".

The field I would like to select records from is called "Model".

Could you please provide me an example using my field and table name?
 
considering that you have something like this:

rs.Open "SELECT Model From Tbl_MainTable",Objconn

This should do it...
Code:
<form method="POST" action="blah.asp">
<p><small><font face="Arial">Values: </font></small>
<select name="group" size="1">
<option value="-Select One-">-Select One-</option>
<%while NOT rs.EOF%> 
<option value="<%=rs("Model")%>"><%=rs("Model")%></option>
<%rs.MoveNext
wend
rs.Close%> 
</select>
<input type="submit" value="Submit" name="B1"></p>
</form>

Note that the first part

<option value="<%=rs("Model")%>"> denotes the value of the selection made by the user....

and the second part <%=rs("Model")%> is just the display in the combo box...

in the above example...both the display and value are the same...

for example if you had something like this...

rs.Open "SELECT Model,ModelID From Tbl_MainTable",Objconn

then the above can be changed as...

Code:
<form method="POST" action="blah.asp">
<p><small><font face="Arial">Values: </font></small>
<select name="group" size="1">
<option value="-Select One-">-Select One-</option>
<%while NOT rs.EOF%> 
[b]<option value="<%=rs("ModelID")%>"><%=rs("Model")%></option>[/b]
<%rs.MoveNext
wend
rs.Close%> 
</select>
<input type="submit" value="Submit" name="B1"></p>
</form>


of course this is all for the convenience when storing or retrieving the information from the database...

let me know if you have any more problems...

-L

 
I'm getting an error:
Code:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/Modified2.asp, line 19


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) 

Page:
GET /Modified2.asp

This is the code I currently have:
Code:
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<% ' FP_ASP -- ASP Automatically generated by a Frontpage Component. Do not Edit.
FP_CharSet = "windows-1252"
FP_CodePage = 1252 %>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Make</title>
</head>

<body>

<form method="POST" action="Modified2.asp">
<p><small><font face="Arial">Values: </font></small>
<select name="group" size="1">
<option value="-Select One-">-Select One-</option>
<%while NOT rs.EOF%> 
<option value="<%=rs("ModelID")%>"><%=rs("Model")%></option>
<%rs.MoveNext 
wend 
rs.Close%> 
</select>
<input type="submit" value="Submit" name="Model"></p>
</form>
<table width="521" border="1" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" cellpadding="0" cellspacing="0" bordercolorlight="#FFFFFF">
  <thead>
 
Do you have any Visual Basic programming experience? Any programming experience at all? I'm not trying to be a jerk, I'm just assesing your level of knowledge.

You need to declaire your vriables and objects before you can use them.

Hope this helps!

gtg.jpg

GTG
 
I do pretty well with VB/VB For Applications. But this is my first attempt at anything ASP or HTML and I’m really unclear on the syntax and structure of it.

Typically I deal with VB For Applications and MS Access 97-02.
 
The syntax and rules are basically the same. You still need to "Dim" the objects and variables. For the Recordset object, try this:

Code:
Dim rs

set rs = server.createobject("ADODB.Recordset")

This will take care of the "Object required: ''
/Modified2.asp, line 19" error.

Hope this helps!

gtg.jpg

GTG
 
I made a new page to start fresh. Once I get this down I can adapt it to my other page.

Code:
<html>

<head>
<% ' FP_ASP -- ASP Automatically generated by a Frontpage Component. Do not Edit.
FP_LCID = 1033 %>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<% ' FP_ASP -- ASP Automatically generated by a Frontpage Component. Do not Edit.
FP_CharSet = "windows-1252"
FP_CodePage = 1252 %>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Drift Gear Stats</title>
</head>

<body>
<%
rs.Open "SELECT Model From Tbl_MainTable",Objconn
%>
<form method="POST" action="Test.asp">
<p><small><font face="Arial">Values: </font></small>
<select name="group" size="1">
<option value="-Select One-">-Select One-</option>
<%while NOT rs.EOF%> 
<option value="<%=rs("Model")%>"><%=rs("Model")%></option>
<%rs.MoveNext
wend
rs.Close%>
</select>
<input type="submit" value="Submit" name="Model"></p>
</form>
<table width="100%" border="1">
  <thead>
    <tr>
      <td><b>Year</b></td>
      <td><b>Make</b></td>
      <td><b>Model</b></td>
    </tr>
  </thead>
  <tbody>
    <!--webbot bot="DatabaseRegionStart" s-columnnames="Year,Make,Model,Displacement,Horsepower,Torque,Source,0-60,0-100,1/4 Mile,RecordID" s-columntypes="202,202,202,202,202,202,202,202,202,202,3" s-dataconnection="DriftGearDatabase" b-tableformat="TRUE" b-menuformat="FALSE" s-menuchoice s-menuvalue b-tableborder="TRUE" b-tableexpand="TRUE" b-tableheader="TRUE" b-listlabels="TRUE" b-listseparator="TRUE" i-listformat="0" b-makeform="TRUE" s-recordsource="Tbl_MainTable" s-displaycolumns="Year,Make,Model" s-criteria="[Make] EQ {Make} +" s-order s-sql="SELECT * FROM Tbl_MainTable WHERE (Make =  '::Make::')" b-procedure="FALSE" clientside suggestedext="asp" s-defaultfields="Make=" s-norecordsfound="No records returned." i-maxrecords="256" i-groupsize="5" botid="0" u-dblib="_fpclass/fpdblib.inc" u-dbrgn1="_fpclass/fpdbrgn1.inc" u-dbrgn2="_fpclass/fpdbrgn2.inc" tag="TBODY" preview="&lt;tr&gt;&lt;td colspan=64 bgcolor=&quot;#FFFF00&quot; align=&quot;left&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;This is the start of a Database Results region.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;" startspan --><!--#include file="_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM Tbl_MainTable WHERE (Make =  '::Make::')"
fp_sDefault="Make="
fp_sNoRecords="<tr><td colspan=3 align=left width=""100%"">No records returned.</td></tr>"
fp_sDataConn="DriftGearDatabase"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=5
fp_fTableFormat=True
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_iDisplayCols=3
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<!--webbot bot="DatabaseRegionStart" endspan i-checksum="17500" --><tr>
      <td>
      <!--webbot bot="DatabaseResultColumn" s-columnnames="Year,Make,Model,Displacement,Horsepower,Torque,Source,0-60,0-100,1/4 Mile,RecordID" s-column="Year" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-MenuFormat preview="&lt;font size=&quot;-1&quot;&gt;&amp;lt;&amp;lt;&lt;/font&gt;Year&lt;font size=&quot;-1&quot;&gt;&amp;gt;&amp;gt;&lt;/font&gt;" startspan --><%=FP_FieldVal(fp_rs,"Year")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="5130" --></td>
      <td>
      <!--webbot bot="DatabaseResultColumn" s-columnnames="Year,Make,Model,Displacement,Horsepower,Torque,Source,0-60,0-100,1/4 Mile,RecordID" s-column="Make" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-MenuFormat preview="&lt;font size=&quot;-1&quot;&gt;&amp;lt;&amp;lt;&lt;/font&gt;Make&lt;font size=&quot;-1&quot;&gt;&amp;gt;&amp;gt;&lt;/font&gt;" startspan --><%=FP_FieldVal(fp_rs,"Make")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="3834" --></td>
      <td>
      <!--webbot bot="DatabaseResultColumn" s-columnnames="Year,Make,Model,Displacement,Horsepower,Torque,Source,0-60,0-100,1/4 Mile,RecordID" s-column="Model" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-MenuFormat preview="&lt;font size=&quot;-1&quot;&gt;&amp;lt;&amp;lt;&lt;/font&gt;Model&lt;font size=&quot;-1&quot;&gt;&amp;gt;&amp;gt;&lt;/font&gt;" startspan --><%=FP_FieldVal(fp_rs,"Model")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="9091" --></td>
    </tr>
    <!--webbot bot="DatabaseRegionEnd" b-tableformat="TRUE" b-menuformat="FALSE" u-dbrgn2="_fpclass/fpdbrgn2.inc" i-groupsize="5" clientside tag="TBODY" preview="&lt;tr&gt;&lt;td colspan=64 bgcolor=&quot;#FFFF00&quot; align=&quot;left&quot; width=&quot;100%&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;This is the end of a Database Results region.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;TR&gt;&lt;TD ALIGN=LEFT VALIGN=MIDDLE COLSPAN=64&gt;&lt;NOBR&gt;&lt;INPUT TYPE=Button VALUE=&quot;  |&lt;  &quot;&gt;&lt;INPUT TYPE=Button VALUE=&quot;   &lt;  &quot;&gt;&lt;INPUT TYPE=Button VALUE=&quot;  &gt;   &quot;&gt;&lt;INPUT TYPE=Button VALUE=&quot;  &gt;|  &quot;&gt;  [1/5]&lt;/NOBR&gt;&lt;BR&gt;&lt;/td&gt;&lt;/tr&gt;" startspan --><!--#include file="_fpclass/fpdbrgn2.inc"-->
<!--webbot bot="DatabaseRegionEnd" endspan i-checksum="62730" --></tbody>
</table>

</body>

</html>
 
And using the above code I get this error:

Code:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/test.asp, line 18

Thank you for all your help.
 
Spyder,

You said that you are experienced in VB? Do you have access to a copy of Visual Studio or Visual InterDev? I would HIGHLY recommend using one of those products to write your ASP over Frontpage. Hell, even Notepad would be better! There are a few packages (that I believe to be free) to assist you in writing ASP. HTML-Kit is one I remember from school.

Hope this helps!

gtg.jpg

GTG
 
I suggest the ASP and ADO tutorials at as they are brief and to the point (and free). It will probably take less than an hour to work through both, and you'll know a lot more of the basics you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top