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!

Saving Array in ASP page?

Status
Not open for further replies.

caherner

Programmer
Nov 12, 2006
7
CA
On an ASP page I am looping through a table in a MYSQL database, which is retrieving a subproduct number based on a product number in the table. What gets outputted on the page in a form is buttons labeled "Rent Disc 1" "Rent Disc 2" "Rent Disc 3". When a button is clicked on, I want the corresponding subproduct number to be passed to the next page. The problem is I do not know how to properly save the subproduct number in a variable each loop through. What is the best way to save it, to be able to pass it to the next page?? The following code does not work:

Code:
Set rsRentalSets = Conn222.Execute("SELECT rentalsets.productID, rentalsets.subproductID, rentalsets.description, products.productName, products.productID " & _
		"FROM rentalsets, products WHERE rentalsets.productID = '" & intProdID & "' AND rentalsets.productID = products.productID AND rentalsets.rental = 'Y' ")
 
i=0

strSubNO = rsRentalSets.subproductID

While Not rsRentalSets.EOF 

	  if rsRentalSets.EOF then
		
      else

	  strDesc = rsRentalSets("description")
	  strName = rsRentalSets("productName")
	  strSubProductID = rsRentalSets("subproductID")

	  response.write "<br>" & strName & " - " & strDesc & "<br>"

%>

<form action="[URL unfurl="true"]http://xxxxxxxxxxxxxxx.asp"[/URL] method="post" id="form" name="form">

<%
strSubNO(i) = strSubProductID
%>

<input type='text' name='passMovie(i)' value='<%= strSubNO(i) %>'>

<input type='submit' value='Rent Now' id='Rent' name='Rent'>
</form>

<%

	  end if

i = i + 1

rsRentalSets.MoveNext
Wend


Thanks in advance.
 
If I'm reading your code correctly, you should be able to add the following to your current code, inside the form, and pass the relevant information to the page submitted to.
Code:
<input type="hidden" name="subproductID" value="<%=strSubProductID%>">

Lee
 
First problem you have above is you are writing a new form every run through the loop. Put the loop inside the form tags so it is unique. You do not need to save the values to an array of var. The way you have it is fine. Just set the value to the textbox of the ID of the product. That way you can query the DB on the ID to get what they selected.

This
Code:
strSubNO = rsRentalSets.subproductID
should be this
Code:
strSubNO = rsRentalSets("subproductID")

but that is not needed either. You are already validating for EOF so you do not need to say If rs.EOF. That's a waist of processing time. Your FORM tag doesn't need the absolute path either. Counters (i = i + 1) are for loops. you're in a while loop. If you need to have a button per textbox then do it with javascript and submit the form via client scripting..ie myForm.submit(); It sounds more like you want to set each textbox to disabled. Then set a button next to each one and if they click the button pass the value of the subproductID to your client side function and dynamically set the textbox to not be disabled. Thus it will pass to the form collection. Otherwise you should not use a text input sense the use can change it and simply write the values out.

Code:
%>
<form action="somewhere.asp" method="post" id="form" name="form">
<%
While Not rsRentalSets.EOF
	%>
	<input type='text' name='<%=rsRentalSets("subproductID")%>' value='<%=rsRentalSets("productName")%>'>
	<%
rsRentalSets.MoveNext
Wend
%>
</form>

The more you open and clsoe with <% %> the slower your code will be also.

This isn't for school is it??

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top