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

Passing variable from page to page

Status
Not open for further replies.

dtran

Programmer
Jun 25, 2001
29
US
I am wondering how do you pass a variable from one page to another? I know how to use the "Page.asp?name=John", but I want to pass a variable I am getting from a database so I don't know what "name" is, so I can't do that, I think. I know about "Request.Form" and "Request.QueryString" but my variable isn't in a textbox and it is somewhat sensitive infomation so I think that rules out both methods. Can anyone help?

Thanks in advance.
 
dtran,

To access the column name, use this syntax in HTML
<%
' your dsn connection and SQL query here

fieldname = objRS.Fields(I).Name
fieldvalue = objRS.Fields(I).Value
' where objRS is your recordset and I the column number

response.write &quot;<input type='hidden' name='xfield' value='&quot; & fieldname & &quot;'&quot;


%>

<input type=&quot;text&quot; name=&quot;<%=fieldname%>&quot; value=&quot;<%=fieldvalue%> >

</body>
</html>

In Nextpage.asp
<%
' Here your retrieving the name of the field
xstring = request.querystring(&quot;xfield&quot;)

' Here your retrieving the value of the field
val = request.querystring(xstring)

%>

Fengshui1998
 
I normally do this:
Code:
'DB Connection and Recordset creation here

'Redirect Page
Response.Redirect &quot;Page.asp?username=&quot; & objRS(&quot;Username&quot;)

'Link with dynamic url
<A href=&quot;Page.asp?username=<%=objRS(&quot;Username&quot;)%>&quot;>Click here</A>

'If objRS(&quot;Username&quot;) is 'John', the redirect will redirect to:
'Page.asp?username=John
'And the link will link to
'Page.asp?username=John
'If objRS(&quot;Username&quot;) is 'Bixarrio', the redirect will redirect to:
'Page.asp?username=Bixarrio
'And the link will link to
'Page.asp?username=Bixarrio

'Close DB and Recordset here
Note: The above code is not meant to be a page. It's an example of 2 scenarios.
 
Oh. Another thing. If you are using your own server, you could also use session variables to pass variables from page to page.

Code:
'//Default.asp ----------------------------------------
'Lotsa stuff
<%
Session(&quot;Username&quot;) = objRS(&quot;Username&quot;)
%>
'More stuff


'//Page.asp -------------------------------------------
'Lotsa stuff
<%
Response.write &quot;Welcome back, &quot; & Session(&quot;Username&quot;)
%>
'More Stuff
 
Thanks that really helped.
What about:
How would I pass it from an onClick event?
And can you call two functions from one onClick event?
I tried <input type=&quot;button&quot; onClick=&quot;call function1(); call function2();&quot;> but that doesn't seem to work.
 

dtran,

You can call a function that has two functions embedded in it.

Cheers
Fengshui1998





<input type=&quot;button&quot; name=&quot;btn1&quot; onclick=&quot;dothis()&quot;>

<script language=&quot;javascript&quot;>
function dothis() {
var x = replace(string, &quot; &quot;, &quot;+&quot;);
var y = morph(x, y);
.....
}

function replace(argvalue, x, y) {
....
....
return
}

function morph(x,y) {
...
...
return
}

</script
 
Thanks alot guys.
It really helped.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top