Calling PHP function in a javascript function

Discussion in 'JavaScript' started by Danielz, Apr 9, 2008.

  1. #1
    Hi, Is it possible to call a php function in the java script function? Plz give me one example..
     
    Danielz, Apr 9, 2008 IP
  2. norfstar

    norfstar Peon

    Messages:
    1,154
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #2
    PHP is server side and JavaScript is client side; so you would need to do use AJAX to call a PHP script that returns the HTML desired and/or runs the code required. For an example, try Googling for "Introduction to AJAX".
     
    norfstar, Apr 9, 2008 IP
  3. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is it possible to save a Google Adword (adword referral to be specific) javascript code, save it as whatevername.js and upload it in the server so that if the url is clicked (whatevername.js) it would redirect to Google landing page of Adword? What is the code for that?
     
    Bohol, Apr 9, 2008 IP
  4. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #4
    I'm not quite sure I understand what you're asking. You want to embed google adwords (did you mean Adsense?) into a page, and have users click on a URL that would count as a(n adsense?) click? Something like Kontera?

    If so, I don't know how that complies with the TOS.

    But in either case, you could just generate your Javascript with your PHP file and have it interact that way.
     
    Louis11, Apr 9, 2008 IP
  5. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi Louis, do you have a sample code of javascript within PHP code?
    I would like to put Google Firefox referral in php.
     
    Bohol, Apr 9, 2008 IP
  6. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #6
    Sorry for the late reply:
    
    <?
    $javascript = '<script>alert("Javascript in PHP!");</script>';
    print $javascript;
    ?>
    
    PHP:
    That should do it for you!
    Cheers,
    Louis
     
    Louis11, Apr 16, 2008 IP
    Bohol likes this.
  7. Danielz

    Danielz Peon

    Messages:
    115
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi, It is working.
     
    Danielz, May 1, 2008 IP
  8. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I cannot use this code for Google adwords. I still need to learn more about PHP and Javascript. Any more input?
     
    Bohol, May 12, 2008 IP
  9. LH08

    LH08 Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It looks like this thread discusses my issue. Can I insert Kontera code into PHP pages? If so how? The code is:

    <script type='text/javascript'>
    var dc_AdLinkColor = '#969600' ;
    var dc_UnitID = 14 ;
    var dc_PublisherID = 12345;
    var dc_adprod = 'ADL' ;
    </script>
    <script type='text/javascript' src='http://kona.kontera.com/javascript/lib/KonaLibInline.js'>
    </script>

    I'm a noob. Thanks.
     
    LH08, Jun 3, 2008 IP
  10. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Just put the code outside the <? and ?> tags of the php script. Or use something like
    echo "
    <script type='text/javascript'>
    var dc_AdLinkColor = '#969600' ;
    var dc_UnitID = 14 ;
    var dc_PublisherID = 12345;
    var dc_adprod = 'ADL' ;
    </script>
    <script type='text/javascript' src='http://kona.kontera.com/javascript/lib/KonaLibInline.js'>
    </script>
    ";
    PHP:
    printf("
    <script type='text/javascript'>
    var dc_AdLinkColor = '#969600' ;
    var dc_UnitID = 14 ;
    var dc_PublisherID = 12345;
    var dc_adprod = 'ADL' ;
    </script>
    <script type='text/javascript' src='http://kona.kontera.com/javascript/lib/KonaLibInline.js'>
    </script>
    ");
    PHP:
     
    xlcho, Jun 3, 2008 IP
  11. akenaten

    akenaten Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hello all before all, this is my first post here, and this post its eaxctly what i was looking for, ive got this function:

    function load_SpecialDays() {
    add_SpecialDay("01-Jun-2008", 'booked')
    add_SpecialDay("4/Jun/2008", 'booked')
    add_SpecialDay("5-Jun-2008", 'booked')
    }

    And this php code:

    <?php
    include 'config.php';
    include 'opendb.php';
    $query = "select arrival from confirmed where room_id = 1";

    $result = mysql_query($query);

    while ($row = mysql_fetch_assoc($result)) {
    list( $anio, $mes, $dia ) = explode( "-", $row['arrival'] );
    echo "add_SpecialDay($dia-$mes-$anio, 'booked')<br>\n";
    }
    ?>

    php code prints on screen this:

    add_SpecialDay(18-06-2008, 'booked')
    add_SpecialDay(03-07-2008, 'booked')
    add_SpecialDay(12-07-2008, 'booked')

    Could i assign this result to the function, i mean could i assign value for this result to include on load_SpecialDays()?

    Thanks in advance.
    R3g@rd$.
     
    akenaten, Jun 4, 2008 IP