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

public shared variable? 1

Status
Not open for further replies.

Kicket

Technical User
Jun 15, 2002
155
US
i want have some group of variable shared by couple of html,and asp files. where should i declare them?

it's like in my html i have some var
then i ll link to an asp page
i want my asp use some of the html Variables
any idea
suggestion,please?
ff
 
you can use hidden form fields to pass them to other pages
<input type=hidden name=&quot;blah&quot; value=variable>
[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
here
<sciprt language=&quot;vbscript&quot;>
dim var1
var1 = &quot;blah&quot;
document.Hidden Values.first value.value = var1
</script>

<form name=&quot;Hidden Values&quot;>
<input type=&quot;hidden&quot; name=&quot;first value&quot;>
</form>

does that clear it up a little?
[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
okay
if i had a variable in my the.html
<sciprt language=&quot;vbscript&quot;>
dim var1
var1 = &quot;blah&quot;
document.Hidden Values.hello.value = var1
</script>

if i want use var1 from &quot;the.html&quot; in my &quot;not.asp&quot;
would be
<input type=&quot;hidden&quot; name=&quot;hello&quot;>
'this declare the variable var1 in my not.asp page?
right?

ff
 
you will need to submit the hidden fields first then call them in a querystring. There are other ways but this may be the easiest rate now. here is a example you can try.
the.html
<html>
<head>
<script language=&quot;vbscript&quot;>
sub hidden()
dim var1
var1 = &quot;blah&quot;
form1.hidden1.value = var1
form1.nothidden.value = var1
alert var1
end sub
</script>
</head>
<body onLoad=&quot;hidden()&quot;>
<form name=&quot;form1&quot; method=&quot;GET&quot;>
<input type=&quot;hidden&quot; name=&quot;hidden1&quot; value=&quot;&quot;>
<input type=&quot;text&quot; name=&quot;nothidden&quot; value=&quot;&quot;>
<input type=submit value=&quot;submit&quot;>
<!-- you can submit onunload or some other way, the button
is a example -->
</form>
</body>
</html>

not.asp
<html>
<head>
<script language=&quot;vbscript&quot;>
var1 = request.querystring(&quot;hidden1&quot;)
alert var1
</script>
</head>
<body>
</body>
</html>

try this and see how it works. I'm sorry if I made a mistake but I'm typing quick got to go. Let me know if you get it. [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
what are those input for???

ff
 
the input is the hidden form field
it is a very common way to pass variables, values to other pages.
the user never sees them.
did you run the code to try it out and see if you understand what I mean?
html or asp really doesn't matter.
it's real easy and straight forward
[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
I placed the input=&quot;text field there jsut in the example to show the idea of the field being hidden. sorry if that made it confusing [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
hey man, i tested ur code
i didn't make another sub hidden()
i already have an textarea and a button
while i click on button, it will call a sub
in that sub
i put ur code in there

dim saddeg
saddeg =abox.value
form1.hidden1.value = saddeg

abox is my input textarea
but it shows object does not support this function

ff
 
okay i got it
hidden1 is the input

ff
 
okay i store the variable in the the.html 's form1.hidden1
fine
but there's seems like to be a promblem to let the asp page read the variable from it
so...

ff
 
seeing as you are calling it in a asp page try it like this in the second page
<html>
<head>
<%
dim var1
var1 = Request.QueryString(&quot;hidden1&quot;)
response.write(var1)

%>

</head>
<body>

</body>
</html>

I am sorry, I forgot to tell you you will need the action in the form to specify the page to submit the hidden values like this
<form name=&quot;form1&quot; method=&quot;GET&quot; action=&quot;not.asp&quot;>

I checked this on my server to double check and it passed it fine.
hope that does it [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
just wanted to add a bit.
If you save all your pages as .asp pages then you can jsut create a global.asa and have session variables in it for use around the site in all pages without having to do things this way. Far easier that way. [thumbsup2]

thought!!
[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
omg. i even tried the exactly same thing
the second page just can't read from first page
i don't have any problem store the var
first page alert var1 did fine
ff
 
give me the code. there has to be something else going on here [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 


see i download the exactly code to my computer
just won't work
;(

i got the variable's to my second page already
but it's not reading

not.asp?hidden1=blah&nothidden=blah&Submit1=submit

this is my second page
i can see the var
it just won't read it

ff
 
here's the.html

<html>
<head>
<script language=&quot;vbscript&quot;>
sub hidden()
dim var1
var1 = &quot;blah&quot;
form1.hidden1.value = var1
form1.nothidden.value = var1
alert var1
end sub
</script>
</head>
<body onLoad=&quot;hidden()&quot;>
<form name=&quot;form1&quot; method=&quot;GET&quot; action=&quot;not.asp&quot; ID=&quot;Form1&quot;>
<input type=&quot;hidden&quot; name=&quot;hidden1&quot; value=&quot;&quot; ID=&quot;Hidden1&quot;> <input type=&quot;text&quot; name=&quot;nothidden&quot; value=&quot;&quot; ID=&quot;Text1&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot; ID=&quot;Submit1&quot; NAME=&quot;Submit1&quot;>
</form>
</body>
</html>

here's not.asp

<html>
<head>
<%
dim ack
ack = request.form1(&quot;hidden1&quot;)
document.write(ack)
%>
</head>
<body>
</body>
</html>


ff
 
need to see some code to try and figure out what is going wrong [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
first make this ID the same as the name
<input type=&quot;text&quot; name=&quot;nothidden&quot; value=&quot;&quot; ID=&quot;Text1&quot;>
<input type=&quot;text&quot; name=&quot;nothidden&quot; value=&quot;&quot; ID=&quot;nothidden&quot;>


then this is asp not javascript
<%
dim ack
ack = request.form1(&quot;hidden1&quot;)
document.write(ack)
%>
needs to look like this and when using the GET method you need response.querystring not form
<%
dim ack
ack = Request.QueryString(&quot;hidden1&quot;)
Response.write(ack)
%>
[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top