Variable problem with multi-use function
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Variable problem with multi-use function

From: Art X <Xlectric@webtv.net>
Date: Mon Jun 13 2005 - 18:21:56 CEST

The reason for this has do to with the nature of WebTV and will be
directed to WebTV users with a conditional so that it will have no
effect on PC users.

I'm trying to create a function that will put focus to a form element
(with a short delay) when the division that it is in is changed from
hidden to visible.

For a one time use, this works:

function showDiv()
{
if (navigator.appName.indexOf("WebTV") != -1)
{
setTimeout("document.getElementById('theinput').focus();", 50);
}
document.getElementById("hiddendiv").style.visibility = "visible";
document.getElementById("visiblediv").style.visibility = "hidden";
}

Both divisions have these embedded CSS rules:

#visiblediv, #hiddendiv {
width: 100%;
height: 100%;
text-align: center;
position: absolute;
left: auto;
top: 65px;
}
#visiblediv {
visibility: visible;
}
#hiddendiv {
visibility: hidden;
}

And in the body:

<a href="javascript:void();" onclick="openDiv(); return false;">Display
The Form</a>

<div id="visiblediv">
division content
</div>

<div id="hiddendiv">
division content including a text link with a function to hide this
division again and a form containing the text input with the id of
"theinput"
</div>

However, I want to use this function more than once. When I try this it
doesn't work:

function showDiv(in_foc)
{
if (navigator.appName.indexOf("WebTV") != -1)
{
setTimeout("document.getElementById(in_foc).focus();", 50);
}
document.getElementById("hiddendiv").style.visibility = "visible";
document.getElementById("visiblediv").style.visibility = "hidden";
}

Then in the body:

<a href="javascript:void();" onclick="openDiv('theinput'); return
false;">Display The Form</a>

hiddendiv becomes visible but the focus() does not work. I realize it
has to do with how I'm addressing the variable, I just can't figure out
what I'm doing wrong.

Later, Art.
Received on Tue Oct 18 02:44:19 2005