Javascript trigger

Discussion in 'Programming' started by fadetoblack22, Oct 19, 2009.

  1. #1
    I have this following script:

    <script type="text/javascript">
    function demoMessage(){
        Shadowbox.open({
            player:     'html',
            content:    '<div style="text-align:center;padding-top:10px;">You\'re using <a href="http://www.shadowbox-js.com">Shadowbox</a>!</div>',
            height:     100,
            width:      200
        });
    }
    </script>
    Code (markup):
    It triggers with a click:
    <a class="option" onclick="demoMessage();">Script-triggered Message</a>

    However I want it to trigger inside an if statement:

    if($CountryCode == "xx"){
    $str = <<<EOD.............
    Code (markup):
    Can someone help?

    thanks.
     
    fadetoblack22, Oct 19, 2009 IP
  2. epikpoker

    epikpoker Well-Known Member

    Messages:
    213
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #2
    Do you mean you want the function to run if your IF statement is met?
     
    epikpoker, Oct 19, 2009 IP
  3. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #3
    yes. correct :)
     
    fadetoblack22, Oct 19, 2009 IP
  4. epikpoker

    epikpoker Well-Known Member

    Messages:
    213
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #4
    can you do something like:

    <?
    if($CountryCode == "xx"){
    echo'<body onload="demoMessage();">';
    }
    else
    {
    echo'<body>';
    }
    ?>

    I have used that a bunch in the past with success. Hope it helps.
     
    epikpoker, Oct 19, 2009 IP
  5. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #5
    This code isn't at the top of the page. Will the "body" work with it?
     
    fadetoblack22, Oct 20, 2009 IP
  6. epikpoker

    epikpoker Well-Known Member

    Messages:
    213
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #6
    Can you move the code? The other option is to put it at the bottom of the page in an onload.
     
    epikpoker, Oct 20, 2009 IP