469,356 Members | 2,249 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

question about hide and show when page is loaded

my job is to check the cookie and then decide if I show a image link
on the page when the page is loaded.

this is what I did:

<html>
<head>
<TITLE>THIS IS TEST </TITLE>

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">

function buttonLoad()
{
if(isTargetPerson == true)
{
var button = document.getElementById("my_button");
button.attachEvent("onClick", markVisit);

}
else

document.getElementById("my_button").style="visibi lity:hidden";

}
function isTargetPerson()
{

if (document.documentElement && (typeof
document.documentElement.style.maxHeight!="undefin ed" )&&
window.XMLHttpRequest && document.epando && isNewbie() )
return true;
else
return false;
}

function isNewbie()
{
if(document.cookie != "")
{
thisCookie = document.cookie.split("; ")

for(i = 0; i< thisCookies.length; i++)
{
if ((thisCookie[i].split("=")[0] == "newbie") &&
(thisCookie[i].split("=")[1] == "false"))
{
document.write("Yan= " + thisCookie[i].split("=")[0] +
"Yan1= " + thisCookie[i].split("=")[1]);
return false
}
}
return true;
}
else
return true;
}

function markVisit()
{
var expDate = new Date;
expDate.setMonth(expireDate.getMonth()+6);
document.cookie = "newbie=false;expires="+expDate.toGMTString()+ ";";

}

</SCRIPT>
</head>

<BODY>

<div id="search">

<INPUT TYPE="image" id="my_button" src="sp_ie7.gif" VALUE="Add
Search Provider" onClick='somefunction;'>

</div>

</BODY>

</html>

but everytime I got the image on the page. I have checked
isTargetPerson() function and it returns false. so that means
document.getElementById("my_button").style="visibi lity:hidden"; did
not do its job.
Anyone could please give me some hints!

Feb 15 '07 #1
6 1367
Lee
zh********@gmail.com said:
if(isTargetPerson == true)
That line doesn't test whether your isTargetPerson function
returns true or false, it just tests whether or not it exists.
It does exist, so you'll always show your button.

If you want the return value, you need to actually invoke the
function, which requires the parentheses:

if ( isTargetPerson() )
Note that it's a waste to compare a boolean to "true".
True is true.
--

Feb 15 '07 #2
Hey, Thank you very much for your reply. isTargetPerson may be a
problem. But my code can come to the else part.

anyway I got a problem here:
document.getElementById("my_button").style="visibi lity:hidden";
I add a line of code at the bottom of the script
window.onLoad="buttonLoad", but It complains getElementById returns a
null. I have no idea about this. Please help!

On Feb 15, 3:48 pm, Lee <REM0VElbspamt...@cox.netwrote:
zhengya...@gmail.com said:
if(isTargetPerson == true)

That line doesn't test whether your isTargetPerson function
returns true or false, it just tests whether or not it exists.
It does exist, so you'll always show your button.

If you want the return value, you need to actually invoke the
function, which requires the parentheses:

if ( isTargetPerson() )

Note that it's a waste to compare a boolean to "true".
True is true.

--

Feb 15 '07 #3
zh********@gmail.com scribed:
>Hey, Thank you very much for your reply. isTargetPerson may be a
problem. But my code can come to the else part.

anyway I got a problem here:
document.getElementById("my_button").style="visib ility:hidden";
document.form.my_button.visibility=hidden;
>
I add a line of code at the bottom of the script
window.onLoad="buttonLoad", but It complains getElementById returns a
null. I have no idea about this. Please help!

On Feb 15, 3:48 pm, Lee <REM0VElbspamt...@cox.netwrote:
>zhengya...@gmail.com said:
if(isTargetPerson == true)

That line doesn't test whether your isTargetPerson function
returns true or false, it just tests whether or not it exists.
It does exist, so you'll always show your button.

If you want the return value, you need to actually invoke the
function, which requires the parentheses:

if ( isTargetPerson() )

Note that it's a waste to compare a boolean to "true".
True is true.

--
--
Ed Jay (remove 'M' to respond by email)
Feb 15 '07 #4
Ed Jay said the following on 2/15/2007 4:29 PM:
zh********@gmail.com scribed:
>Hey, Thank you very much for your reply. isTargetPerson may be a
problem. But my code can come to the else part.

anyway I got a problem here:
document.getElementById("my_button").style="visib ility:hidden";

document.form.my_button.visibility=hidden;
document.getElementById('myButton').style.visiblit y="hidden";

Will probably work better :)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 15 '07 #5
Randy Webb wrote:
Ed Jay said the following on 2/15/2007 4:29 PM:
>zh********@gmail.com scribed:
>>Hey, Thank you very much for your reply. isTargetPerson may be a
problem. But my code can come to the else part.

anyway I got a problem here:
document.getElementById("my_button").style="visi bility:hidden";


document.form.my_button.visibility=hidden;


document.getElementById('myButton').style.visiblit y="hidden";

Will probably work better :)
document.getElementById('myButton').style.display= "none";

would be even better...
Mick

Feb 15 '07 #6
Randy Webb scribed:
>Ed Jay said the following on 2/15/2007 4:29 PM:
>zh********@gmail.com scribed:
>>Hey, Thank you very much for your reply. isTargetPerson may be a
problem. But my code can come to the else part.

anyway I got a problem here:
document.getElementById("my_button").style="visi bility:hidden";

document.form.my_button.visibility=hidden;

document.getElementById('myButton').style.visibli ty="hidden";

Will probably work better :)
Much. <b sheepish g>. :-)
--
Ed Jay (remove 'M' to respond by email)
Feb 16 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.