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

mutliple forms in the same ASP page

Status
Not open for further replies.

techzone12

Technical User
Joined
Aug 24, 2005
Messages
32
Location
US
I have an ASP page called "sample.asp" that has two forms. The first form (form1) has a dropdown list box and a submit button. When selecttion is made and the submit is clicked ,tha user selection is passed to the same page (sample.asp).
I am using:
<form name="form1" method="post" action="sample.asp">
'
'
'
<input type="submit" name="Submit" value="Show Columns">
</form>

The data entered is then used to populate a dropdown list box in form2.

The second form also has a submit button. When it's clicked, I want all the entries form form1 and form2 to be passed to a seocond page "Display.asp" for action.
<form name="form2" method="post" action="Display.asp">
'
'
'
<input type="submit" name="Submit2" value="Submit Form">

How can I do this?

Thanks



 
ok, so you want to populate your second dropdown box depending on the selection made in the first dropdown box...

you dont need two form for it...and this situation is handled in a different...i would suggest you to read this FAQ. It has the complete code...try running the sample code first and them adapt to your requirements....post back if you have any questions...

here is FAQ... faq333-1498

also refer to this link
hope this helps....

-DNG
 
I tried the code posted in the FAQ. The code looked like it should work, and seemed to be efficient.

The code has some typos however.....It wouldn't run as is.
I corrected the typos.. and tested the asp page. Unfortunatelly it did not work. I don't know what I am missing?

The is the code I am using:

<%@language=vbscript%>
<%option explicit%>
<%
'OUR SQL, CONNECTION, AND RECORDSET STUFF
dim con, strCon, MakeSql, ModelSQl, rsMake, rsModel

'OUR USER DEFINED STUFF
dim curMake, curModel

'INSTANTIATE THE OBJECTS TO BE USED
set con = server.createObject("ADODB.Connection")
set rsMake = server.createObject("ADODB.Recordset")
set rsModel = server.createObject("ADODB.Recordset")

'HERE I'LL USE A DATA SOURCE NAME CALLED
' 'makeModel' TO OPEN OUR CONNECTION
strCon = "Provider=SQLOLEDB; Data Source= eng_server;"_
+ "Initial Catalog = testDB;User ID=myID; Password=myPswrd "

'strCon = "DSN=makeModel;UID=userID;PWD=password"

'THIS IS WHERE WE EVALUATE OUR Request.Form.Count
' TO DECIDE WHAT TO DO
if (Request.Form.Count = 0) then

'THIS IS A FIRST LOAD OF THE PAGE
' WE DON'T NEED TO GRAB ANY USER DATA

'**note that I'm giving our fields aliases here**
' I'm doing this so that we can use the same
' subprocedure to create our listboxes later on
' in the code. Keep an eye on how we do that.

makeSQL = "SELECT make AS description"
makeSQL = makeSQL & " FROM make ORDER BY make"

modelSQL = "SELECT model AS description"
modelSQL = modelSQL & " FROM model ORDER BY model"

else

'THIS IS A RECURSIVE LOAD
' WE NEED TO SEE WHAT THE USER HAS CHOSEN

curMake = Request.Form("make")
curModel = Request.Form("model")

'NOW WE WILL BUILD OUR DYNAMIC SQL STATEMENT

'LET'S STILL SELECT ALL MAKES, SO THAT THE USER CAN
' SELECT A DIFFERENT ONE IF THEY WISH
makeSQL = "SELECT make AS description FROM make"
makeSQL = makeSQL & " ORDER BY make"

'LET'S ONLY SELECT THE MODELS THAT CORRESPOND TO
' THE USER'S CHOICE
modelSQL = "SELECT model AS description"
modelSQL = modelSQL & " FROM model"
modelSQL = modelSQL & " WHERE make = '" & curMake & "'"
modelSQL = modelSQL & " ORDER BY model"

end if

'SO AT THIS POINT, NO MATTER WHETHER THE LOAD IS FIRST,
' OR RECURSIVE, WE HAVE THE APPROPRIATE SQL STATEMENTS
' BUILT UP, SO LET'S NOW OPEN OUR
' CONNECTION AND RECORDSETS

con.Open strCon

rsMake.Open makeSQL, con
rsModel.Open modelSQL, con
%>

<HTML>
<HEAD>
<TITLE>Dynamic List Box Test</TITLE>

<SCRIPT LANGAUAGE=javaScript>
//THIS IS THE FUNCTION THAT WILL BE CALLED
// onChange FOR EITHER OF THE LIST BOXES
// ALL IT WILL DO IS SUBMIT THE FORM FOR US

function submitMe(){
document.theForm.submit();
}
</SCRIPT>

</HEAD>
<BODY>

<FORM NAME=theForm METHOD=post ACTION=makeModel.asp>

<%
'I'M GOING TO USE A SUBPROCEDURE TO WRITE OUT
' OUR SELECTS -- SENDING IT THE APPROPRIATE VARIABLES
' TO WRITE THE PROPER SELECT

call makeSelect(rsMake,curMake,"make")
call makeSelect(rsModel,curModel,"model")
%>

</FORM>
</BODY>
</HTML>
<%
'TAKE OUT THE TRASH
set rsMake = nothing
set rsModel = nothing
set con = nothing

sub makeSelect(lRS,curValue,selectName)

with response

.Write("<SELECT NAME=" & selectName)
.Write(" onChange=""submitMe();"">" & vbcr)

'LET'S PUT A DEFAULT SELECTION IN THAT
' WILL AUTOMATICALLY SHOW IF
' THE USER HAS NOT YET MADE A CHOICE
.Write("<OPTION VALUE=none>SELECT ONE</OPTION>" & vbcr)

'LOOP THROUGH OUR RECORDSET,
' OUTPUTTING WHATEVER'S THERE
while not lRS.eof
.Write("<OPTION VALUE=""" & lRS("description") & "")

'CHECK TO SEE IF THE CURRENT VALUE WAS SELECTED
' BY THE USER AND SELECT IT IF SO
if curValue = lRS("description") then
.Write(" selected")
end if

.Write(">" & lRS("description") & "</OPTION>" & vbcr)

lRS.MoveNext
wend

.Write("</SELECT>")

end with

end sub
%>

Thanks

 
can you tell us what exact error message are you getting...just saying not working wouldnt help much to suggest you a solution...

-DNG
 
Sorry about that. I know I should have explained better. I am not getting and error message. I get the page to run but it's displaying as follows in the drop down list box:

SELECT ONE
Honda


SELECT ONE
Balzer
Camry
Celica

I was expecting to see:
SELECT ONE
GM
Honda
Toyota

SELECT ONE
Blazer
Buick
Caprice
Accord
Civic
Camry
celica

When I select the only option, Honda, nothing happens. i.e the same exact page will display again.

Thanks






 
Oops. I need to correct myself
When I select "Honda", the page does reload. This is what is displayed however:

SELECT ONE
Honda




 
try this: and tell me what happens...

Code:
.Write("<OPTION VALUE="""[red]""[/red] & lRS("description") & "")

i have just added couple of double quotes...

-DNG
 
it just has to do with some quotes...just play around with the code and correct some typos and you will be good to go...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top