PDA

View Full Version : accessing the hidden variable from other file



phani
Nov 27th, 2002, 12:45 PM
how to access the hidden variable stored in one file in the other html file. or how to access the parameters passed on perform some action in other html file

beetle
Nov 27th, 2002, 04:17 PM
Huh? A hidden variable? Can you be more specific? What are you trying to accomplish?

brothercake
Nov 27th, 2002, 05:38 PM
perhaps he's talking about passing data through query strings

beetle
Nov 27th, 2002, 06:31 PM
Yes, that seems to make sense with the vocabulary he used. If that's the case, phani, you can use this function I wrote to extract all the GET parameters into an associative array
function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split("&");
var nameVal, val;
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split("=");
val = (typeof nameVal[1] == 'undefined') ? '' : unescape(nameVal[1]);
getVars[unescape(nameVal[0])] = val;
}
return getVars;
}
var _GET = parseGetVars();Of course, you can use any variable you like, I just chose _GET because it closely mimics the PHP counterpart.

phani
Nov 28th, 2002, 07:13 AM
how to pass the parameters from one simple html page to another simple html page which is not having any relation between them....without having any server concept...
can i get any sample application with code

Roelf
Nov 28th, 2002, 07:18 AM
if you donīt open the second page from the first one, use cookies. do a search in this forum for "cookies" it should return "some" results

glenngv
Nov 28th, 2002, 08:56 AM
...or use window.name if you are not using frames/iframes

set it in a page:
window.name="blah";


you can access it in another page even if it is not opened from the page where you set the window.name:

alert(window.name)

phani
Nov 28th, 2002, 09:18 AM
Hi glenn i have two html pages like this but i am not getting the value of the hidden variable in the secod form..even we assign some name to the window here is my two html pages can u help me

first html file (one.html)

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<script>
window.name = "hello";
alert(window.name)
</script>
<BODY BGCOLOR="#FFFFFF">
<form action = "two.html">
<input type="hidden" name = "vamsi" value = "hi">
<input type="submit" name = "go" value = "Submit">
</form>
</BODY>
</HTML>

second html file (two.html)

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<script>
alert(hello.doucment.forms[0].vamsi.value)
</script>
</BODY>
</HTML>


can i get that vamsi.value in the second html page...if so plzz let me know how it should be done...

glenngv
Nov 28th, 2002, 09:24 AM
in first page:

<script>
window.onload = function(){window.name=document.forms[0].vamsi.value};
</script>
<BODY BGCOLOR="#FFFFFF">
<form action = "two.html">
<input type="hidden" name = "vamsi" value = "hi">
<input type="submit" name = "go" value = "Submit">
</form>


in second page:
<script>
alert(window.name)
</script>