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

Forward and Backward button on table

Status
Not open for further replies.

acewilli

IS-IT--Management
Apr 11, 2003
98
US
Hello, I need to add a button to my table that will switch between content for the table only. I don't want to have to create a new ASP page in order to display the Forward or Backward data. I thought it was easy but I'm having a hard time getting it to work. Below is my code for my existing page. The next/previous button is the button that I want to use to display other data from my database. I store comments for each month in the database and want to be able to go back and forth between the monthly comments. The name of this ASP page is USERID(FromDB)_comments.asp. Thank you in advance.

Code:
<!-- #includes file="includes/dbconn.inc" -->
<title>Comments for - Mr. Smith</title>
<%
	dim strmonthly
	dim stryearly
	dim strday
	
	strmonthly=datepart("m",date)
	stryearly=datepart("yyyy",date)
	strday=datepart("d",date)	
	
	If strmonthly="1" then
		strmonthly="January"
	elseif strmonthly="2" then
		strmonthly="February"
	elseif strmonthly="3" then
		strmonthly="March"
	elseif strmonthly="4" then
		strmonthly="April"
	elseif strmonthly="5" then
		strmonthly="May"
	elseif strmonthly="6" then
		strmonthly="June"
	elseif strmonthly="7" then
		strmonthly="July"
	elseif strmonthly="8" then
		strmonthly="August"
	elseif strmonthly="9" then
		strmonthly="September"
	elseif strmonthly="10" then
		strmonthly="October"
	elseif strmonthly="11" then
		strmonthly="November"
	elseif strmonthly="12" then
		strmonthly="December"
	else
	end if	

	If Request.QueryString("s") = "" Or Request.QueryString("s") = "sn" Then
		sortBy = "member"
	Elseif Request.QueryString("s") = "tp" Then
		sortBy = "tpoints"
	Elseif Request.QueryString("s") = "mm" Then
		sortBy = "memo"
	End If
	
	strSQL = "Select * FROM Home ORDER BY "& sortBy
	Set rsStatus = Server.CreateObject("ADODB.Recordset")
	rsStatus.open strSQL, db

%>
<h1>CSSO-PT Team "Dare to Soar" Comments:</h1>
<hr>
<center>
[b]'WHAT DO I DO HERE FOR MY PREVIOUS BUTTON TO PULL MY OTHER DATA FROM THE DATABASE??
	<FORM>
	<INPUT TYPE="BUTTON" VALUE="Previous Month" ONCLICK="window.location.href='../cssopt/"& rsHome("ID") &"_comments.asp'"><INPUT TYPE="BUTTON" VALUE="Home" ONCLICK="window.location.href='../cssopt/Home.asp'"> 
<INPUT TYPE="BUTTON" VALUE="Next Month" ONCLICK="window.location.href='../cssopt/"& rsHome("ID") &"_comments.asp'">
	</FORM>
[/b]
</center>
<form name="frmMain" action=rsHome("ID") &"_comments.asp?s=<%=Request.QueryString("s")%>" method="get">
		<table class="table1">
		<tr>
			<td class="td1"><center><a class="style1">Team Member - Mr. Smith - <%= strmonthly %> Comments</a></center></td>
		</tr>
		<%
			str2SQL = "Select * FROM Home"
			Set rsStatus = Server.CreateObject("ADODB.Recordset")
			rsStatus.open str2SQL, db
	
		While Not rsStatus.eof
			If rsStatus("ID")="1" then
				Response.Write "<tr><td class=td1 align=center><textarea class=style2 ROWS=25 COLS=125 Wrap=Physical name=txtMemo"& rsStatus("ID") &">"& rsStatus("ttmemo") & chr(13) & rsStatus("tt2memo") & chr(13) & rsStatus("tt3memo") & chr(13) & rsStatus("tt4memo") & chr(13) & rsStatus("tt5memo") & chr(13) & rsStatus("tt6memo") & chr(13) & rsStatus("tt7memo") & chr(13) & rsStatus("tt8memo") & chr(13) & rsStatus("tt9memo") & chr(13) & rsStatus("tt10memo") &"</textarea></td></tr>"
			End If
		rsStatus.movenext
		Wend
		%>
	</table>
<hr>
</form>
</body>
 
onpnt, was I vague in my question or do you post the General FAQ and 5 steps to asking a question with all of your comments?

I wanted to be sure as I rarely post questions in the ASP forum. I appreciate your guidance.

Thanks,

acewilli
 
That would be my signature. Sorry it appears as if I do that everytime. Did you read them? They are pretty good :)

General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Yes...I figured it out after I submitted my comment. Sorry about that. They are pretty good. I am having a lot of trouble getting this to work. Is there not a way to create a drop down menu with each month listed and have the page pull the information from the database based on the month selected from the menu? I'm not sure what to do at this point as my brain is fried. Below is my horrible attempt at getting this to work. As you can see I'm very lost and confused. Hopefully from the code you can tell what I'm trying to do....I hope. My frmMain is not at all what it needs to be. I'm not even sure how to use it correctly. I would like to be able to do this with what I have without having to create a new ASP page for each month. Any help is greatly appreciated.

Code:
<!-- #includes file="includes/dbconn.inc" -->
<title>Comments for - Mr. Smith</title>
<%
	dim strmonthly
	dim stryearly
	dim strday
	dim strmonthnow
	
	strmonthly=datepart("m",date)
	stryearly=datepart("yyyy",date)
	strday=datepart("d",date)	
	
	If strmonthly="1" then
		strmonthly="January"
	elseif strmonthly="2" then
		strmonthly="February"
	elseif strmonthly="3" then
		strmonthly="March"
	elseif strmonthly="4" then
		strmonthly="April"
	elseif strmonthly="5" then
		strmonthly="May"
	elseif strmonthly="6" then
		strmonthly="June"
	elseif strmonthly="7" then
		strmonthly="July"
	elseif strmonthly="8" then
		strmonthly="August"
	elseif strmonthly="9" then
		strmonthly="September"
	elseif strmonthly="10" then
		strmonthly="October"
	elseif strmonthly="11" then
		strmonthly="November"
	elseif strmonthly="12" then
		strmonthly="December"
	else
	end if	

	If Request.QueryString("s") = "" Or Request.QueryString("s") = "sn" Then
		sortBy = "member"
	Elseif Request.QueryString("s") = "tp" Then
		sortBy = "tpoints"
	Elseif Request.QueryString("s") = "mm" Then
		sortBy = "memo"
	End If
	
	strSQL = "Select * FROM Home ORDER BY "& sortBy
	Set rsStatus = Server.CreateObject("ADODB.Recordset")
	rsStatus.open strSQL, db

%>
<h1>CSSO-PT Team "Dare to Soar" Comments:</h1>
<hr>
<%
	dim filtermonth

	Response.write "<center>"
	Response.write "<FORM>"
	Response.write "<INPUT TYPE=BUTTON VALUE=Home ONCLICK=window.location.href='../cssopt/Home.asp'>"
	Response.write "</FORM>"
%>
<form name="frmMain" action="1_comments.asp?s=<%=Request.QueryString("s")%>" method="get">
	<select name="select">
	<option>Choose Month</option>
	<option value="ttmemJan">January</option>
	<option value="ttmemFeb">February</option>
	<option value="ttmemMar">March</option>
	<option value="ttmemApr">April</option>
	<option value="ttmemMay">May</option>
	<option value="ttmemJun">June</option>
	<option value="ttmemJul">July</option>
	<option value="ttmemAug">August</option>
	<option value="ttmemSep">September</option>
	<option value="ttmemOct">October</option>
	<option value="ttmemNov">November</option>
	<option value="ttmemDec">December</option>
	</select>

		<table class="table1">
		<tr>
			<td class="td1"><center><a class="style1">Team Member - Mr. Smith - <%= strmonthly %> Comments</a></center></td>
		</tr>
		<%
			str2SQL = "Select * FROM Home"
			Set rsStatus = Server.CreateObject("ADODB.Recordset")
			rsStatus.open str2SQL, db
			
	If Request.Form("select") <> "" then

			FilterMonth = Request.Form("select")
			response.write filtermonth

		While Not rsStatus.eof
			If rsStatus("ID")="1" then
				Response.Write "<tr><td class=td1 align=center><textarea class=style2 ROWS=25 COLS=125 Wrap=Physical name=txtMemo"& rsStatus("ID") &">"& rsStatus(filtermonth) & chr(13) &"</textarea></td></tr>"
			End If
		rsStatus.movenext
		Wend
	
	else
	
		While Not rsStatus.eof
			If rsStatus("ID")="1" then
				Response.Write "<tr><td class=td1 align=center><textarea class=style2 ROWS=25 COLS=125 Wrap=Physical name=txtMemo"& rsStatus("ID") &">"& rsStatus("ttmemo") & chr(13) & rsStatus("tt2memo") & chr(13) & rsStatus("tt3memo") & chr(13) & rsStatus("tt4memo") & chr(13) & rsStatus("tt5memo") & chr(13) & rsStatus("tt6memo") & chr(13) & rsStatus("tt7memo") & chr(13) & rsStatus("tt8memo") & chr(13) & rsStatus("tt9memo") & chr(13) & rsStatus("tt10memo") &"</textarea></td></tr>"
			End If
		rsStatus.movenext
		Wend
	end if		
		%>
	</table>
<hr>
</form>
</body>
 
Okay...here is what I got to work.

Code:
<!-- #includes file="includes/dbconn.inc" -->
<title>Comments for - Mr. Smith </title>
<SCRIPT LANGUAGE=javascript>
<!--
	function Check()
	{
		if(document.form1.TextToSearch.value == 0)
		{
			document.form1.TextToSearch.focus();
			return false;
		}
	}
//-->
</SCRIPT>
<%
	dim strmonthly
	dim stryearly
	dim strday
	dim strmonthnow
	
	strmonthly=datepart("m",date)
	stryearly=datepart("yyyy",date)
	strday=datepart("d",date)	
	
	If strmonthly="1" then
		strmonthly="January"
	elseif strmonthly="2" then
		strmonthly="February"
	elseif strmonthly="3" then
		strmonthly="March"
	elseif strmonthly="4" then
		strmonthly="April"
	elseif strmonthly="5" then
		strmonthly="May"
	elseif strmonthly="6" then
		strmonthly="June"
	elseif strmonthly="7" then
		strmonthly="July"
	elseif strmonthly="8" then
		strmonthly="August"
	elseif strmonthly="9" then
		strmonthly="September"
	elseif strmonthly="10" then
		strmonthly="October"
	elseif strmonthly="11" then
		strmonthly="November"
	elseif strmonthly="12" then
		strmonthly="December"
	else
	end if	

	If Request.QueryString("s") = "" Or Request.QueryString("s") = "sn" Then
		sortBy = "member"
	Elseif Request.QueryString("s") = "tp" Then
		sortBy = "tpoints"
	Elseif Request.QueryString("s") = "mm" Then
		sortBy = "memo"
	End If
	
	strSQL = "Select * FROM Home ORDER BY "& sortBy
	Set rsStatus = Server.CreateObject("ADODB.Recordset")
	rsStatus.open strSQL, db

%>
<h1>CSSO-PT Team "Dare to Soar" Comments:</h1>
<hr>
<%
	dim filtermonth

	Response.write "<center>"
	Response.write "<FORM>"
	Response.write "<INPUT TYPE=BUTTON VALUE=Home ONCLICK=window.location.href='../cssopt/Home.asp'>"
	Response.write "</FORM>"
%>
<FORM METHOD=POST id=form1 action="1_comments.asp" name=form1 onsubmit="return Check();">
	<select name="select">
	<option>Choose Month</option>
	<option value="ttmemJan">January</option>
	<option value="ttmemFeb">February</option>
	<option value="ttmemMar">March</option>
	<option value="ttmemApr">April</option>
	<option value="ttmemMay">May</option>
	<option value="ttmemJun">June</option>
	<option value="ttmemJul">July</option>
	<option value="ttmemAug">August</option>
	<option value="ttmemSep">September</option>
	<option value="ttmemOct">October</option>
	<option value="ttmemNov">November</option>
	<option value="ttmemDec">December</option>
	</select>
<INPUT TYPE=SUBMIT VALUE="Show Month" id=SUBMIT1 name=SUBMIT1>	
</form>
<form name="frmMain" action="1_comments.asp?s=<%=Request.QueryString("s")%>" method="get">

		<table class="table1">
		<tr>
			<td class="td1"><center><a class="style1">Team Member - Mr. Smith - <%= strmonthly %> Comments</a></center></td>
		</tr>
		<%
			str2SQL = "Select * FROM Home"
			Set rsStatus = Server.CreateObject("ADODB.Recordset")
			rsStatus.open str2SQL, db
			
	If Request.Form("select") <> "" then

			FilterMonth = Request.Form("select")

		While Not rsStatus.eof
			If rsStatus("ID")="1" then
				Response.Write "<tr><td class=td1 align=center><textarea class=style2 ROWS=25 COLS=125 Wrap=Physical name=txtMemo"& rsStatus("ID") &">"& rsStatus(filtermonth) & chr(13) &"</textarea></td></tr>"
			End If
		rsStatus.movenext
		Wend
	
	else
	
		While Not rsStatus.eof
			If rsStatus("ID")="1" then
				Response.Write "<tr><td class=td1 align=center><textarea class=style2 ROWS=25 COLS=125 Wrap=Physical name=txtMemo"& rsStatus("ID") &">"& rsStatus("ttmemo") & chr(13) & rsStatus("tt2memo") & chr(13) & rsStatus("tt3memo") & chr(13) & rsStatus("tt4memo") & chr(13) & rsStatus("tt5memo") & chr(13) & rsStatus("tt6memo") & chr(13) & rsStatus("tt7memo") & chr(13) & rsStatus("tt8memo") & chr(13) & rsStatus("tt9memo") & chr(13) & rsStatus("tt10memo") &"</textarea></td></tr>"
			End If
		rsStatus.movenext
		Wend
	end if		
		%>
	</table>
<hr>
</form>
</body>
 
one more shot...

I know your profile says you are in management which lends itself an interesting aspect on progamming the correct way but you really need to take some time (a day or two) and read up on some programming concepts and methods. That doesn't mean ASP development but programming in general. There are some great books and tutorials out there for this.

I want to be honest because I hope in the long run it will help you do a better job for all of us as anything one of us does reflects our abilities as programmings and our fields in general to our audience (being the users and other IT fields)

OK. Here are some tips

Dynamic creation of code. Use tables in your database to loop and build strings as needed. Use counters and markers to create dynamic controls (listbox's etc...)
Learn proper SQL and performance considerations. Never use *. That is kind of a first semester college mistake that should have been corrected by the second semester. It's horrid on performance and bad form. Learn looping concepts. The technique is NOT just for going through record collections but what it is as a method of dynamically looking out at something or validating something. Learn basic HTML standards and coding stanards in general. You have no " " around any of your attributes in your basic HTML output. That small factor is not cool at all. Naming conventions! Try some. Form1 won't help the person that has to maintain this code if you get hit by a bus tomorrow morning. Research form collection for client/server web development. QueryStrings are great but you are not validating the user alering your URL so you are not using the method correctly or in a stable manner.
Learn correct methods for conditional statements. The double loop with the If statement is out there. you should have one loop nesting the If statement. That one is kind of odd and I don't think I've seen someone do that before.

Take a hour or so to study the below code and some of the styles I show you. Compare the size or potential size I should say of the script to your other ones and see the difference in that factor alone. And think about chanign it later on. how easy it may be compared to something like that If statement to get the month value. Which I noticed you kind of ignored in my prior replies so I'm hoping you won't ignore this reply in all. I also noticed you had a thread in August that showed methods to the same effect but you seemed to not allpy them. Please! This makes us all look bad and programming is still or I hope considered the top field in IT. don't ruin that for the world and make us all drag and drop programmers.

I commented the code below. Not sure if it works and or any syntax errors are in there but that was not the point of giving it to you
Code:
<html>
<head>
<script language="javascript">
function submitIt() {
//function to do that actual submit fo the form
document.frmMain.submit();
}
</script>
</head>
<body>
<%
'in order to submit a form to itself you simply
'put the page name in the action attrib.
'then change the submit to a button (or use hidden fields
'and check to see if the button value was passed in the
'form collection

If Request.Form("Formsubmit") <> "" Then
'form was submitted so lets do something

'build my sql statement NOT using * because it is SLOW
'WHERE clause to see what we need to return
Dim sqlQuery : sqlQuery = "SELECT column2,column3 FROM Home " & _
			  "WHERE column1 = '" & Request.Form("selectMonth") & "'"

'connection object
Set conn = Server.CreateObject("ADODB.Connection")
'connection string
Dim connStr : connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
						 Server.MapPath ("db2.mdb") & ";"

'and open it
conn.Open connStr
'create my recordset
Set rs = conn.Execute(sqlQuery)

	'if I have values
	If NOT rs.EOF Then
		Response.Write "The data returned is listed below<br>"
		Response.Write "Column2 is " & rs("column2") & "<br>"
		Response.Write "Column3 is " & rs("column3") & "<br>"
		'dynamically see what needs to go in the textarea
		Response.Write "This data was shown because " & Request.Form("selectMonth") & _
				   		" was selected from the listbox<br>"
		Response.Write "And I almost forgot the textarea <br>" & request.Form("txtMemo")
	Else
	'if I don't have values
		Response.Write "Sorry I found nothing in the DB"
	End If

	'CLEAN UP!!!!
	Set rs = Nothing
	conn.Close
	Set conn = Nothing
Else
'form was not submitted so show it to them

	'a little thinking on making it easy to get month names
	Sub monthNames()
	'need a counter sense there are more than 1 month in a year
	Dim count : count = 1

	Do While count <= 12
		'build the option
		Response.Write "<option value='" & MonthName(Month(cDate(count & "/01/1900"))) & "'>"
		Response.Write MonthName(Month(cDate(count & "/01/1900"))) & "</option>"
		count = count + 1
	Loop
	End Sub
	%>
	<form name="frmMain" action="really.asp" method="post">

	<select name="selectMonth">
	<% monthNames() %>
	</select>


	<%
	' marker declaration for example only
	Dim marker : marker = 1
	'here I would do some more database work and loop
	'through the fields but I won't cause this is an example

	'sqlQuery = "SELECT column1,column2,column3 FROM Home"

	'While Not rsStatus.eof
		Response.Write "<tr><td class=td1 align=center>"
		Response.Write "<textarea"
		Response.Write " name=txtMemo>"
		If marker = 1 then
			Response.Write "I did something cause it was 1"
		Else
			Response.Write "I did not do something"
		End If
		Response.Write "</textarea></td></tr>"
	'rsStatus.movenext
	'Wend
%>
<input type="button" value="Submit" onClick="submitIt();">
<input type="hidden" name="Formsubmit" value="submitted">
</form>
<%
End If
%>
</body>


____________ signature below ______________
General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
onpnt, thank you for the tips. I have not mentioned that I am very new to this and this was done by another person and I am just trying to maintain it and make things work that were not made to work by the original programmer. I would really like to clean it up and your tips will definitely help with that. I'm the poor guy that got stuck with maintaining after the other guy was hit by the bus. One reason I'm having so much trouble with this is because I'm having a hard time deciphering what this other guy did. I guess I need to focus more on cleaning it up rather than just adding to the mayhem so if my work gives me the time I will be sure to do so. Again...thank you for helping me out with this and in the future I will make sure to explain the whole situation as I did not explain that I did not do this myself.

Thanks again,

acewilli
 
Matter of fact....I'll just get it all cleaned up and then revisit all of this later. I knew I should have done it sooner but I was being pushed to get some new features added to it. I'll just go through and clean it up as it should be. Thanks again. If I see the guy that was hit by the bus I'll ask him what he was thinking. I believe he was a high school student so there you go.
 
And yes....it was the same guy that quit that I was working on his junk back in August as well. I'll get it cleaned up and come back later. This isn't even my job...since he quit I'm the only one that will even attempt to mess with this junk.
 
By the way, what earlier comment did I ignore? The link that you gave me? I just went back after you said that and did not see an earlier comment except for the one below.

onpnt (Programmer) 14 Sep 06 8:09
Paging Recordset
General FAQ FAQ333-2924
5 steps to asking a question FAQ333-3811

Is that what you are talking about? I'll be back after I spend my weekend cleaning this mess up. Next time I will let the post know if I am the original programmer or not. Most everything I've posted at tek-tips is from the guy hit by the bus. I just need to fix it and make it work so I can get back to my real job.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top