question about hide and show when page is loaded

Z

zhengyan11

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="visibility:hidden";

}


function isTargetPerson()
{

if (document.documentElement && (typeof
document.documentElement.style.maxHeight!="undefined" )&&
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.split("=")[0] == "newbie") &&
(thisCookie.split("=")[1] == "false"))
{
document.write("Yan= " + thisCookie.split("=")[0] +
"Yan1= " + thisCookie.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="visibility:hidden"; did
not do its job.


Anyone could please give me some hints!
 
L

Lee

(e-mail address removed) 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.


--
 
Z

zhengyan11

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="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!
 
R

Randy Webb

Ed Jay said the following on 2/15/2007 4:29 PM:
(e-mail address removed) scribed:


document.form.my_button.visibility=hidden;

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

Will probably work better :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top