Jump to content

select from a drop down box


mckenzie

Recommended Posts

Helloi've got this code that displays 18 drop down boxes and populaes them wiv 18 tables from an access databse. Within these tables there is 3 fields (id, name, price). i would like to be able to select from a drop down box and have the price of that item displayed to the roght of it!!!! how would i got about doing this?i've seen tutorials on the internet to populate drop down boxes but not to be able to slect from it.?here's my code.sorry about the Drd's at the bottom(a bit of a waist of space)<%Dim connDim CmdPopulatefoodDim SQLdim FieldNamedim TableNameset Conn = Server.createobject("ADODB.Connection")conn.open "PROVIDER=Microsoft.jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("Project.mdb") & ";" Set rs = Server.CreateObject("ADODB.RecordSet")%><%Sub Fillcombo (TableName, name)SQL= "SELECT DISTINCT " & name & " FROM " & (TableName)rs.Open SQL, conn If Not rs.EOF Then Do While Not rs.EOF %> <Option value=<%= rs("name")%>><%= rs("name")%></Option> <% rs.MoveNext LoopEnd Ifrs.CloseEnd Sub%><html><body><form method="POST" action="default.asp"><Select Name="Drd1"><% Call Fillcombo("BAKERYandCAKES", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("BEERCIDERALCOPOPS", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("BISCUITSSNACKSandSWEETS", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("BREAKFASTCEREALS", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("COOKINGINGREDIENTS", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("DAIRYEGGSandCHEESE", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("FRESHFRUIT", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("FROZENCHIPSandVEG", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("FROZENDESERTICECREAM", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("FROZENMEATFISHandPOULTRY", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("FROZENREADYMEALSPIZZA", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("MEATFISHandPOULTRY", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("READYMEALSandPIZZA", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("SOFTandHOTDRINKS", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("SPIRITS", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("TINSPACKETSandJARS", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("VEGSALADSandDIPS", "name") %></Select><p></p><p></p><br> <Select Name="Drd1"><% Call Fillcombo("WINES", "name") %></Select><p></p><p></p><br> <input type="submit" value="Submit"></form></body></html> :)

Link to comment
Share on other sites

Helloi've got this code that displays 18 drop down boxes and populaes them wiv 18 tables from an access databse. Within these tables there is 3 fields (id, name, price). i would like to be able to select from a drop down box and have the price of that item displayed to the roght of it!!!!
Try this Change the function as
Sub Fillcombo (TableName, name, value)SQL= "SELECT " & name & " , "& value &" FROM " & (TableName)rs.Open SQL, conn If Not rs.EOF Then    Do While Not rs.EOF         %> <Option value=<%= rs("value")%>><%= rs("name")%></Option>        <%        rs.MoveNext    LoopEnd Ifrs.CloseEnd Sub

Then in ur form use the following

<P><Select Name="Drd1" OnChange=" Fn_Drd_Change('Drd1','Txt1')"><% Call  Fillcombo("BAKERYandCAKES", "name") %></Select><INPUT Name="Txt1" Value=""></P>..

Please use different name for all dropdowns and text boxesnow right a function in javascript

function Fn_Drd_Change(Combo, Text){        eval("document.forms(0)."+ Text +".value = document.forms(0)."+ Combo +".value");}

I didn't try it but will work

Link to comment
Share on other sites

shouldn't the "value" be "price". or is this an added variable name?

So sorry U r rightIve change the code. Change the function as
Sub Fillcombo (TableName, name, price)SQL= "SELECT " & name & " , "& price&" FROM " & TableNamers.Open SQL, conn If Not rs.EOF Then    Do While Not rs.EOF         %> <Option value=<%= rs("price")%>><%= rs("name")%></Option>        <%        rs.MoveNext    LoopEnd Ifrs.CloseEnd Sub

Then in ur form use the following

<P><Select Name="Drd1" OnChange=" Fn_Drd_Change('Drd1','Txt1')"><% Call  Fillcombo("BAKERYandCAKES", "name","price") %></Select><INPUT Name="Txt1" Value=""></P>..

Please use different name for all dropdowns and text boxesfunction in javascriptHere value is right word

function Fn_Drd_Change(Combo, Text){        eval("document.forms(0)."+ Text +".value = document.forms(0)."+ Combo +".value");}

I didn't try it but will work

Link to comment
Share on other sites

where would i put this function and the browser doesn't seem to recognise this { symbol. sorry to be a pain.Here value is right wordCODEfunction Fn_Drd_Change(Combo, Text){ eval("document.forms(0)."+ Text +".value = document.forms(0)."+ Combo +".value");}

Link to comment
Share on other sites

where would i put this function and the browser doesn't seem to recognise this { symbol. sorry to be a pain.Here value is right wordCODEfunction Fn_Drd_Change(Combo, Text){      eval("document.forms(0)."+ Text +".value = document.forms(0)."+ Combo +".value");}

U might have recognise that this is javascript function .So u have to write it in the script tagLike---
<Html>           <Head>                      <script>                              function Fn_Drd_Change(Combo, Text)                               {.....write the function here......}                      </Script>           </Head>             <%   Put Your ASP function/Code here              %>           <Body><Form>                        Put your dropdowns here           </Form></Body></Html>

I think this will serve ur purposeMy explanation skill is not so good.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...