PDA

View Full Version : sending/receiving variable thru html url



canandaigua
Jul 19th, 2006, 04:45 PM
I was reading (http://www.javascriptkit.com/javatutors/send1.shtml) a tutorial about sending objects from one page to another. I seem to have the sending part okay; it's the receiving part I'm having trouble with.

I want to receive a variable (either the word hide or show) and use that to make a layer visible or hidden in Dreamweaver mx.

Here is the code from the sending page:

<body>
<p>
<a href="cross.htm?show" target="_blank">red</a>
</p>
</body>

Here is the code from the receiving page:

<head>
<script language="JavaScript" type="text/JavaScript">
function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
var location=window.location.search;
var red=location.substring(1);
tell(text);
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}
//-->
</script>
</head>

<body onload="MM_showHideLayers('One','',red,'Two','','hide')">

There are two layers (One and Two) and they are defined as hidden.

Any ideas?

subhailc
Jul 19th, 2006, 05:04 PM
simplify :)


location.search
that just means "the contents of the address bar, starting from the last question mark".


to hide a layer, set it's style.display to "none"


function hide(target){
target.style.display="none";
};
to show it, set style.display to anything else (or nothing at all)


function show(target){
target.style.display="";
};

so in your onload, get the variable from the address bar

var visible = window.location.search;

then get rid of the question mark, which is the character at the 0th position - so change it to a substring of itself starting at the first character instead


visible = visible.substring(1);

if that string turns out to be "show", call the show function


if(visible==="show") show(element);

otherwise, hide it


else hide(element);

canandaigua
Jul 19th, 2006, 07:39 PM
It works! I'm so happy.
The only thing I had to change was:

target.style.visibility="none";

When Dreamweaver first defined the layers it used the term visibility rather than the term display.

Thanks.