question about hide and show when page is loaded

Discussion in 'Javascript' started by zhengyan11@gmail.com, Feb 15, 2007.

  1. Guest

    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!
    , Feb 15, 2007
    #1
    1. Advertising

  2. Lee Guest

    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.


    --
    Lee, Feb 15, 2007
    #2
    1. Advertising

  3. Guest

    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!



    On Feb 15, 3:48 pm, Lee <> wrote:
    > 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, 2007
    #3
  4. Randy Webb Guest

    Ed Jay said the following on 2/15/2007 4:29 PM:
    > 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="visibility:hidden";

    >
    > document.form.my_button.visibility=hidden;


    document.getElementById('myButton').style.visiblity="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/
    Randy Webb, Feb 15, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo Birnbach [MS]
    Replies:
    0
    Views:
    3,301
    Marcelo Birnbach [MS]
    Jun 28, 2003
  2. Udo Corban
    Replies:
    0
    Views:
    3,817
    Udo Corban
    Jan 23, 2004
  3. vcuankitdotnet

    Show/Hide Multiple User Controls on Page

    vcuankitdotnet, May 16, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    557
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    May 17, 2007
  4. paul
    Replies:
    1
    Views:
    450
    Thomas 'PointedEars' Lahn
    Oct 26, 2007
  5. ll
    Replies:
    2
    Views:
    627
    Thomas 'PointedEars' Lahn
    May 1, 2008
Loading...

Share This Page