473,666 Members | 2,264 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="JAVAS CRIPT" TYPE="TEXT/JAVASCRIPT">

function buttonLoad()
{
if(isTargetPers on == true)
{
var button = document.getEle mentById("my_bu tton");
button.attachEv ent("onClick", markVisit);

}
else

document.getEle mentById("my_bu tton").style="v isibility:hidde n";

}
function isTargetPerson( )
{

if (document.docum entElement && (typeof
document.docume ntElement.style .maxHeight!="un defined" )&&
window.XMLHttpR equest && document.epando && isNewbie() )
return true;
else
return false;
}

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

for(i = 0; i< thisCookies.len gth; 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.setMont h(expireDate.ge tMonth()+6);
document.cookie = "newbie=false;e xpires="+expDat e.toGMTString() +";";

}

</SCRIPT>
</head>

<BODY>

<div id="search">

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

</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.getEle mentById("my_bu tton").style="v isibility:hidde n"; did
not do its job.
Anyone could please give me some hints!

Feb 15 '07 #1
6 1470
Lee
zh********@gmai l.com said:
if(isTargetPers on == 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.getEle mentById("my_bu tton").style="v isibility:hidde n";
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...@gmai l.com said:
if(isTargetPers on == 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********@gmai l.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.getEl ementById("my_b utton").style=" visibility:hidd en";
document.form.m y_button.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...@gma il.com said:
if(isTargetPers on == 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********@gmai l.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.getEl ementById("my_b utton").style=" visibility:hidd en";

document.form.m y_button.visibi lity=hidden;
document.getEle mentById('myBut ton').style.vis iblity="hidden" ;

Will probably work better :)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript 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********@gmai l.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.getE lementById("my_ button").style= "visibility:hid den";


document.form. my_button.visib ility=hidden;


document.getEle mentById('myBut ton').style.vis iblity="hidden" ;

Will probably work better :)
document.getEle mentById('myBut ton').style.dis play="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********@gmai l.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.getE lementById("my_ button").style= "visibility:hid den";

document.form. my_button.visib ility=hidden;

document.getEl ementById('myBu tton').style.vi siblity="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
3036
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 way to do it would be to have hidden content under each question, something like this : What is the first letter of the alphabet?
4
7994
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) document.layers.visibility = 'visible'; else if (document.all) { document.all.style.visibility = 'visible';
0
2094
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 some stuff in the main display area. The stuff to display is one of many assemblies loaded at the opening of the application by Activator.CreateInstance, because I want it independant of the main application, as a plugin. All assembly are loaded...
3
1253
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 program I use the following code: Dim extAssembly As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("D:\testload\TestLoad\TestLoad\bin\Debug\testload.exe") Dim extForm As Form = extAssembly.CreateInstance("TestLoad.form1",...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6191
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1769
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.