473,508 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1463
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3022
by: Nigel Molesworth | last post by:
I've Googled, but can't find what I need, perhaps I asking the wrong question! I want a "FAQ" page on a web site, I hate those pages that scroll you to the answer so and I figured that a good...
4
7981
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
0
2079
by: Efkas | last post by:
I have a full custom application with some widged extending Controls like Label and PictureBox. I build a menu with these widgets. When I click on one of them, it calls a function to display...
3
1249
by: John Wright | last post by:
How can I set the property of a loaded Assembly using reflection. My Shell program will log in a person and retrieve a list of all programs the person can use. When the shell program launches a...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.