two fucntions trigger by onClick

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

  1. Guest

    Hey,

    what I try to do is when a user clicked an image button on my
    site, I use onClick to trigger a dialog box and at the same time I use
    button.attach("onClick", savecookie) to mark this visitor so that next
    time he comes back I can recognize him.If he did not click this image
    button on my site, next time I would treat him as a new visitor.

    My dialog box works as I expected but it seems that savecookie
    function does not do its job since I could not find any cookies
    stored. I am using IE7. Anyone has any idea about this? It means that
    I cannot trigger two functions from one onclick?


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

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

    function buttonLoad()
    {
    var button = document.getElementById("my_button");

    if(isTargetPerson())
    {

    button.attachEvent("onClick", markVisit);

    }
    else {
    button.style.visibility="hidden";
    }

    }

    function isTargetPerson()
    {
    if (document.documentElement && (typeof
    document.documentElement.style.maxHeight!="undefined" )&&
    window.XMLHttpRequest && isNewbie() )
    return true;
    else
    return false;
    }

    function isNewbie()
    {
    var allcookies = document.cookie;

    var pos = allcookies.indexOf("newbie=");
    //alert(pos);

    if (pos == -1)
    return true;

    else {
    var start = pos + 7;
    var end = allcookies.indexOf(";", start);
    if(end == -1) end = allcookies.length;
    var value = allcookies.substring(start, end);
    if (value == "false")
    return false;
    }

    }

    function markVisit()
    {
    var today = new Date();
    today.setFullYear(today.getFullYear() + 1);

    document.cookie = "newbie=false;expires=" + today.toGMTString();


    }


    </SCRIPT>
    </head>

    <BODY>

    <div id="search">
    <INPUT TYPE="image" id="my_button" src="sp_ie7.gif"
    VALUE="somevalue" onClick=somefunction");'>
    </div>

    <script language="javascript"> window.onLoad=buttonLoad(); </script>

    </BODY>

    </html>
    , Feb 16, 2007
    #1
    1. Advertising

  2. RobG Guest

    On Feb 17, 1:18 am, wrote:
    > Hey,
    >
    > what I try to do is when a user clicked an image button on my
    > site, I use onClick to trigger a dialog box and at the same time I use
    > button.attach("onClick", savecookie) to mark this visitor so that next
    > time he comes back I can recognize him.If he did not click this image
    > button on my site, next time I would treat him as a new visitor.
    >
    > My dialog box works as I expected but it seems that savecookie
    > function does not do its job since I could not find any cookies
    > stored. I am using IE7. Anyone has any idea about this? It means that
    > I cannot trigger two functions from one onclick?


    Yes you can. The easiest way though is to call one function from the
    other, then you only need to attach one handler.

    >
    > <html>
    > <head>
    > <TITLE>THIS IS TEST </TITLE>
    >
    > <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">


    The language attribute is deprecated, keep type.

    [...]

    > <BODY>
    >
    > <div id="search">
    > <INPUT TYPE="image" id="my_button" src="sp_ie7.gif"
    > VALUE="somevalue" onClick=somefunction");'>

    ----------------------------^-----------^

    It's always a good idea to start with valid markup. I think you
    wanted something like:

    ... onclick="somefunction();">


    > </div>
    >
    > <script language="javascript"> window.onLoad=buttonLoad(); </script>


    Javascript is case-sensitive, try:

    window.onload = ...


    There may be other errors.


    --
    Rob
    RobG, Feb 17, 2007
    #2
    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. Willem Oosthuizen

    Aborting Fucntions

    Willem Oosthuizen, Jul 10, 2003, in forum: VHDL
    Replies:
    2
    Views:
    1,047
  2. Divyang M
    Replies:
    4
    Views:
    998
    Divyang M
    Feb 17, 2005
  3. Muzzy

    Time management fucntions

    Muzzy, Dec 24, 2003, in forum: C++
    Replies:
    1
    Views:
    364
    Jeff Schwab
    Dec 24, 2003
  4. DS
    Replies:
    2
    Views:
    182
    Bob Barrows
    Jan 7, 2004
  5. Mike Gratee

    Programatically trigger an onClick event?

    Mike Gratee, Jul 15, 2004, in forum: Javascript
    Replies:
    15
    Views:
    361
    Berislav Lopac
    Jul 20, 2004
Loading...

Share This Page