Question About Calling a Function

Discussion in 'PHP' started by epic1231, Dec 24, 2009.

  1. #1
    Hey everyone, I have a code that I am trying to insert into my application.

    To give an idea before posting hte code, this is an RPG game. When a user gains a level they get a special notice which is displayed "Congrats you leveled up blah"

    What I am trying to do is make this a popup, I have the popup code already and am trying to insert the function to be called automatically (it does not work off an onclick since a user can do jobs and other things without leveling up)

    Here is the code

    
        if( $levelUpdate == 1 && opendiv(s0) ) {
            if( $skillPointEarn > 0 ) {
    ?>
    <script>
    function opendiv(div){
    document.getElementById(div).setStyle('display', 'block');  
    }
    
    function closediv(div){
    document.getElementById(div).setStyle('display', 'none'); 
    }
    </script>
    <?
                $str = '<div id="s0" style="width:300px; height:300px; border:#FFFF00 solid 3px; background-color:#000000; color:#FFFFFF; font-size:16px; position:absolute; display:none; margin-left:200px;"><div class=noticeBox><P class=successP>Congratulations!</P><H2>You leveled up and are now Level '.$pirate->level.'! <br /><br />You earned '.$skillPointEarn.' skill points <br /><br />Your Energy, Health and Stamina Have Been Refilled <br /><br /><input name="Next" type="button" id="button" class="levelupsubmitButton" value="Tell Your Friends & Give Special Bonus!" onclick="publishPost(); return false;"/>  |  <a style="color:#FF0000" onclick="closediv('s0'); return false;" ><img src="/icons/attackicon.png" />Close</a></table></A></H2></td></tr></table></H2></div></div>';
    
                $logText = 'Your level updated to <B>'.$pirate->level.'</B> and you earned <B>'.$skillPointEarn.'</B> skill points!';
                add_news( $logText, $u );
    
            }
            else {
    
                $str = '<div class=noticeBox><P class=successP>Congratulations!</P><H2>Your level updated to '.$pirate->level.'!</H2></div><script> refresh_stat("stats_bar"); </script>'';
            }
            $pirate->save();
        }
    
    PHP:
    I was just playing with the opendiv(s0) code and tried it in the top if call, but the output I am getting is

    Fatal error: Call to undefined function opendiv() in soa/include/userinc.php on line 124

    Any suggestions?

    Thanks in advance and Happy Holidays to Everyone who reads this!
     
    epic1231, Dec 24, 2009 IP
  2. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Opendiv is a function located in the javascript code not the PHP. If you want to run Javascript functions in PHP you need to create an emulated javascript function in the PHP. If you want to do the vice-versa you need to use AJAX.

    So to recap:

    To run javascript functions in PHP you need to create an emulated function in PHP
    To run PHP functions in javascript you can use AJAX
     
    Last edited: Dec 24, 2009
    Brandon_R, Dec 24, 2009 IP
  3. sjgold

    sjgold Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Also the JS interpreter that FB allows is limited. Which could also effect this.
    If you need help Bill hit me up on email.
     
    sjgold, Dec 29, 2009 IP