iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-06-2006, 02:51 PM
WebProWorld New Member
 
Join Date: Feb 2006
Posts: 12
jpdeveloper RepRank 0
Default ASP-form passing parameter values into another file??

I just started using ASP not sure of all the values or if implementing them correctly. I'm having trouble being able to pass my user's selection from two chain drop boxes (which the options are displayed by querying the Access database) and as parameters into my next sql statement. I have the form posting into another file but unable to capture the selected parameters into the next sql's where clause. I appreciate any help or advice anyone can give.. Thanks in advance.
Here is the first file (the user's page selection)
If this might help..

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit

dim objConn, objRS, objRS2, strSQL

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS2 = Server.CreateObject("ADODB.Recordset")

objConn.ConnectionString = Server.MapPath("bulletindb.mdb")
objConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objConn.Open

Sub showDropDownList(c, r, table)
	
	strSQL = "SELECT DISTINCT(month) FROM " & table & " ORDER BY month"
	Set r = c.Execute(strSQL)
	if r.eof = false then
	Response.Write "<form name=""form1"" action=""test_post.asp"" method=""post"">"
	Response.Write "<select name=""dropdownlist"">" & vbCrLf
	Response.Write "<option selected=""selected"" value="""">Select a Month:</option>"
		While r.EOF = false
			Response.Write "<option value=""bulletin_dropdown_menu.asp"">" _
			& r.Fields("month").Value & "</option>" & vbCrLf
		r.movenext
		Wend
	end if
	Response.Write "</select></form>" & vbCrLf
	
End Sub

Sub showDropDownList2(c, r, table)

	strSQL = "SELECT DISTINCT(year) FROM " & table & " ORDER BY year ASC"
	Set r = c.Execute(strSQL)
		if r.eof = false then
	Response.Write "<form name=""form2"" action=""test_post.asp"" method=""post"">"
	Response.Write "<select name=""dropdownlist2"">" & vbCrLf
	Response.Write "<option selected=""selected"" value="""">Select a Year:</option>"
		While r.EOF = false
			Response.Write "<option value=""bulletin_dropdown_menu.asp"">" _
			& r.Fields("year").Value & "</option>" & vbCrLf
		r.movenext 
		Wend
	end if
	Response.Write "<input type=""submit"" value=""Search"">" & vbCrLf
	Response.Write "</select></form>" & vbCrLf
	
End Sub
%>

<html>
<body>



First choose the bulletin month and the select the year</p>
<table width="200">
<tr> 
<td>Select Month:</td>
<td>Select Year:</td>
</tr><tr>
<td><%call showDropDownList(objConn, objRS, "bulletintable")%></td>


<td><%call showDropDownList2(objConn, objRS2, "bulletintable")%></td></tr>
</table>

</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 02-06-2006, 07:22 PM
ADAM Web Design's Avatar
WebProWorld 1,000+ Club
 
Join Date: Dec 2003
Location: Toronto, Ontario, Canada
Posts: 2,181
ADAM Web Design RepRank 1
Default

The problem isn't just your ASP, but the outputted HTML. Don't worry though...you're far from the only person to have this difficulty. I'd say half the select boxes I see, when recalled, are guilty of the same sin as it were.

But...it's an easy enough fix.

First off, when your ASP code retrieves values from the form, it looks at the value attribute of the option tag first.

In every single iteration of your loops that create your listboxes, your value is "bulletin_dropdown_menu.asp". This will be what your ASP code will retrieve when you pass it back.

What you want is something like this:
Code:
for i = 1 to R.Recordcount ' If possible, use for loops because they have an obvious finite ending.  RecordCount should be a self-explanatory recordset attribute.
     Response.Write "<option value=""" & R ("Month") & """" ' you don't need the .Fields or the .value.  They're just code and time wasters.  Simplify, man.
     if R ("Month") = Request.Form ("dropdownlist") then ' It's this line that compares your old value to your new value.
          Response.Write " selected=""selected"""
     end if
     Response.Write ">" & R ("Month") & "</option>" & VbCrLf ' the only point of the vbCrLf is to ensure that your outputted HTML code shows one option value per line.  It just makes things neater.
Next
Alternatively, <option>R ("Month")</option> would work, as long as you didn't assign a value other than R ("MONTH") to your option value.

A few tips for you as an ASP newbie:

1) Response.WRite is your friend. Use it to spit things out at every opportunity.

2) View Source is also your friend. Always view your source to see what happened vs. what you would expect.

3) Response.End can also be used to stop an ASP page dead in its tracks, rather than let it go through all the way. This can be useful if you only want to debug a section of code.

4) Any time you open an object, be sure to close the option and set it to nothing, in order to free up the memory used by that object. If you don't, your server will hang on to it for as long as it wants, and you don't have any control.

5) Write all objects to variables when possible. It'll make debugging and object manipulation so much easier.

e.g. Name = Request.Form ("Name")
Expiry_Date = RS ("Expiry_Date")

As you go on, you'll discover that ASP, if used correctly, can really speed up development time. Use custom subs and functions (as you have done) at every opportunity, and try to write ones that will be reusable.
Reply With Quote
  #3 (permalink)  
Old 02-07-2006, 01:04 PM
WebProWorld New Member
 
Join Date: Feb 2006
Posts: 12
jpdeveloper RepRank 0
Default

Well it is all over welling right now trying to learn asp while trying to produce the correct results at the same time. Thanks for all those tips it was the easy general breakdown of asp which I can relate to other language concepts. I think I'm going to need all the help I can get until I can get a good understanding how it works/reads with other languages.
I have a question with the value "r"? I think I have the recordset or an object set up wrong maybe because when I call the value in the test_post.asp file it states that it is undefined. I did have it working properly but I started changing too much around in the file to try and get a better understand. So I don’t know what I did to "upset" the file so much. Trying to keep it simple..just not working for right now.

This is what I have...

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit

dim objConn, objRS3, strSQL

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS3 = Server.CreateObject("ADODB.Recordset")

objConn.ConnectionString = Server.MapPath("bulletindb.mdb")
objConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objConn.Open

strSQL = "select month, year, link_name, link_filename, post_desc "
strSQL = strSQL & "from bulletintable"
strSQL = strSQL & "where month='"& r (month) &"' and year='"& r (year) &"'"

objRS3.Open strSQL, objConn

response.write("" & objRS3("month") & "&nbsp"  )
response.write("" & objRS3("year") & "
" )

objRS3.movefirst
do while not objRS3.eof

response.write "<a href=""" & objRS3("link_filename") & " target=""_self"">"
response.write objRS3("link_name") & "</a>" & "" 
response.write(" - "& objRS3("post_desc") & "
")

objRS3.movenext

on error resume next

if the_year <> clng(objRS3("year")) then

act.close

end if
loop

set objRS3=nothing
objRS3.close
%>
<html>

</html>
I thought I had to change up how I set the obj's but it just made me get more errors within the file. I just don't know the direction I should go in to make this work?

I really appreciate your help ..thank you in advance.
Reply With Quote
  #4 (permalink)  
Old 02-07-2006, 06:06 PM
WebProWorld New Member
 
Join Date: Feb 2006
Posts: 12
jpdeveloper RepRank 0
Default

Ok..I know I been asking the about the same topic but I'm having a hard time figuring where I'm going wrong at. I have been using my "View Source" and realizing that alot of values were not getting passed or not set up properly as I assumed they were. Therefore I fixed both files and might have be looking at them way too long but I think everything is being passed correctly but am still getting an error on the SQL stating:
Wrong number of arguments or invalid property assignment: 'month'
I just don't see where I'm passing it through wrong or do I have too much going on that it doesn't understand what I want it to do. Some advice please..

bulletin_dropdown_menu.asp
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit

dim objConn, objRS, objRS2, strSQL

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS2 = Server.CreateObject("ADODB.Recordset")

objConn.ConnectionString = Server.MapPath("bulletindb.mdb")
objConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objConn.Open

Sub showDropDownList(c, r, table)
	
	strSQL = "SELECT DISTINCT(month) FROM " & table & " ORDER BY month"
	Set r = c.Execute(strSQL)
	if r.eof = false then
	Response.Write "<form name=""form1"" action=""test_post.asp"" method=""post"">"
	Response.Write "<select name=""dropdownlist"">" & vbCrLf
	Response.Write "<option selected=""selected"" value="& r ("month") &">Select a Month:</option>"
		While r.EOF = false
		if r ("month") = Request.Form ("dropdownlist") then 
          Response.Write " selected=""selected"""
     end if 
			Response.Write "<option value="& r ("month") &">" _
			& r ("month") & "</option>" & vbCrLf
		r.movenext
		Wend
	end if
	Response.Write "</select></form>" & vbCrLf
	
End Sub

Sub showDropDownList2(c, r, table)

	strSQL = "SELECT DISTINCT(year) FROM " & table & " ORDER BY year ASC"
	Set r = c.Execute(strSQL)
		if r.eof = false then
	Response.Write "<form name=""form2"" action=""test_post.asp"" method=""post"">"
	Response.Write "<select name=""dropdownlist2"">" & vbCrLf
	Response.Write "<option selected=""selected"" value=""year"">Select a Year:</option>"
		While r.EOF = false
			if r ("year") = Request.Form ("dropdownlist2") then 
          Response.Write "year selected=""selected"""& r ("year") &""
     end if  
			Response.Write "<option value="& r ("year") &">" _
			& r ("year") & "</option>" & vbCrLf
		r.movenext 
		Wend
	end if
		Response.Write "</select></form>" & vbCrLf
	
End Sub

Sub showBulletinSearch(c, r, table)
		Response.Write "<form name=""form3"" action=""test_post.asp"" method=""post"">"		
		Response.Write "<input type=""submit"" name=""bulletinsearch"" value=""Search"">" & vbCrLf
		Response.Write "</select></form>" & vbCrLf
End Sub
%>

<html>
  

Select the Bulletin "Month" and the cooresponding 4 digit "Year" that you would like to view.</p>
      <table cellpadding="0" cellspacing="10" border="0" width="200" class="style3">
        <tr>
          <td><%call showDropDownList(objConn, objRS, "bulletintable")%></td>
          <td><%call showDropDownList2(objConn, objRS2, "bulletintable")%></td>
          <td><%call showBulletinSearch(objConn, objRS2, "bulletintable")%></td>
        </tr>
      </table>
  </html>
test_post.asp
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit

dim objConn, objRS3, strSQL

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS3 = Server.CreateObject("ADODB.Recordset")

objConn.ConnectionString = Server.MapPath("bulletindb.mdb")
objConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objConn.Open

strSQL = "select month, year, link_name, link_filename, post_desc "
strSQL = strSQL & "from bulletintable"
strSQL = strSQL & "where month="& r (month) &" and year='"& r (year) &"'"

Sub Header (c, r3)

Set r3 = c.Execute(strSQL)

response.write("" & r3("month") & "&nbsp"  )
response.write("" & r3("year") & "
" )

End Sub

Sub Body(c, r3)

Set r3 = c.Execute(strSQL)

r3.movefirst
do while not r3.eof

response.write "<a href=""" & r3("link_filename") & " target=""_self"">"
response.write r3("link_name") & "</a>" & "" 
response.write(" - "& r3("post_desc") & "
")

r3.movenext

on error resume next

if the_year <> clng(r3("year")) then

act.close

end if
loop

set r3=nothing

End Sub

r3.close
objConn.close

%>
<html>


<%call showHeader(objConn, objRS3)%></p>


<%call showBody(objConn, objRS3)%></p>
</html>
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 11:29 PM.



Search Engine Optimization by vBSEO 3.3.0