View Full Version : sending/receiving variable thru html url

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:

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

Here is the code from the receiving page:

<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);
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; }

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

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

Any ideas?

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

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){
to show it, set style.display to anything else (or nothing at all)

function show(target){

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);

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


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