...

View Full Version : Passing variables



garrettb
01-18-2003, 03:22 AM
I am working on a simple page that passes variables from check boxes on one page to another page. Forgive my lack of knowledge, I am a newbie. Is there a way to have the values that were passed, dynamically stack themselves? I am using the follwing code to show the values that were passed:

<table align=center width="480">
<tr>
<!-- assign hidden field values -->
<input type=hidden name=terracotta value="<%=terracotta%>">
<input type=hidden name=chamois value="<%=chamois%>">
<input type=hidden name=redwood value="<%=redwood%>">
<input type=hidden name=jade value="<%=jade%>">
</tr>
<tr>
<%=terracotta%>
<%=chamois%><br>
<%=redwood%><br>
<%=jade%br><br>
</tr>
</table>

This work, but if I only choose redwood on the first page it stays where it is with space for the first two values that weren't passed above it. Is it possible to have the values stack one on top of another even if there were values in between them?
Any help will be greatly appreciated!

Mhtml
01-18-2003, 04:01 AM
I would use the IF statement and the LEN statement bundled with a sub routine.



sub Write(TheVar, Space)
If Space = 0 Then
response.write(TheVar)
Else
response.write("<br>"&TheVar)
End If
End Sub

If len(terracotta) > 0 Then
Write terracotta, 0
Prev = 1
End If
If Len(chamois) > 0 Then
Write chamois, Prev
End If
If Len(redwood) > 0 Then
Write redwood, Prev
End If
If Len(jade) > 0 Then
Write jade, Prev
End If


Replace the below with that..


<%=terracotta%>
<%=chamois%><br>
<%=redwood%><br>
<%=jade%>

garrettb
01-18-2003, 05:30 PM
Thanks for such a quick response.
When I replace the code, with the sub routine and if...then statements, the code shows up on my asp page when I go to it. It isn't actually showing values. Am I doing something wrong?

Here is my code:
<--
<% @LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<%
'COMMENTS
'--START SET VARIABLES, SERVER-SIDE FUNCTIONS, REQUIRED PARAMETERS
'Declare Variables
Dim terracotta,chamois,redwood,jade

'Get Form Variables
terracotta = Request("terracotta")
chamois = Request("chamois")
redwood = Request("redwood")
jade = Request("jade")
'--START PRESENTATION
%>
<HTML>
<HEAD>
<TITLE>Title</TITLE>
</HEAD>
<BODY>
<table align=center width="480">
<tr>
<!-- assign hidden field values -->
<input type=hidden name=terracotta value="<%=terracotta%>">
<input type=hidden name=chamois value="<%=chamois%>">
<input type=hidden name=redwood value="<%=redwood%>"> <input type=hidden name=jade value="<%=jade%>">
</tr>
<tr>
<font face=Arial, Helvetica, San Serif size=2><b>General Request Information</b><BR>

sub Write(TheVar, Space)
If Space = 0 Then
response.write(TheVar)
Else
response.write("<br>"&TheVar)
End If
End Sub

If len(terracotta) > 0 Then
Write terracotta, 0
Prev = 1
End If
If Len(chamois) > 0 Then
Write chamois, Prev
End If
If Len(redwood) > 0 Then
Write redwood, Prev
End If
If Len(jade) > 0 Then
Write jade, Prev
End If
</tr>
</table>
</BODY>
</HTML>

garrettb
01-19-2003, 10:01 PM
Before the code that I listed above, would I use the script statement before the code or the function statement?

Morgoth
01-19-2003, 11:34 PM
I would think you would place the code here:


chamois = Request("chamois")
redwood = Request("redwood")
jade = Request("jade")
'--START PRESENTATION
_HERE_
%>
<HTML>
<HEAD>
<TITLE>Title</TITLE>


But I think you would change Write into a variable that will store the data.

whammy
01-20-2003, 02:06 AM
I'm still confused... what do you mean by "dynamically stack themselves"?

If you're only trying to display variables that have a value (i.e. someone checked the checkbox on the first page), you can do this:


terracotta = Request.Form("terracotta")
If terracotta <> "" Then Response.Write(terracotta & "<br />" & vbCrLf)

etc. Not sure if I would create a function for something as simple as Response.Write, though, Mhtml... ;)

:confused:

garrettb
01-20-2003, 01:38 PM
Thanks for all the replies, like I said I am very new to all this and I am probably not using the correct terminology.

whammy, what I mean by dynamically stack is: in the first portion of code I posted, if 2 check boxes were checked on the first page and I displayed the values on the second, and there were 2 boxes unchecked in between the two that were checked the spaces for the two unchecked were left between the 2 displayed values.

What I am trying to accomplish is, if 2 boxes are checked, with boxes between them unchecked, that when I display the values on the second page the values will be displayed without any spaces between them for values that aren't displayed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum