1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Inserting javascript code into PHP??

Discussion in 'PHP' started by momrocks, May 11, 2009.

  1. #1
    I can't figure out how to do this, for the life of me. Can anyone please help me out with this?
     
    momrocks, May 11, 2009 IP
  2. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to echo "each line of the script and or escape \"quotes\" ";

    if you post the script some will give you an example
     
    pixmania, May 11, 2009 IP
  3. somanweb

    somanweb Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    I dont think, its a complex one.

    You can use the echo function for this.

    You can simply write the code like below

    echo '<script langauage="javascript">';
    echo 'alert("Testing");
    echo '</script>';

    If you not mean the above problem, keep post in this forum.
    We will try to help you.

    Soman
     
    somanweb, May 11, 2009 IP
  4. momrocks

    momrocks Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here's the code I'd need to insert into a PHP page. It's from Google's Friend Connect.

    <!-- Include the Google Friend Connect javascript library. -->
    <script type="text/javascript" src="http://www.google.com/friendconnect/script/friendconnect.js"></script>
    <!-- Define the div tag where the gadget will be inserted. -->
    <div id="div-xxxxxx" style="width:276px;border:1px solid #cccccc;"></div>
    <!-- Render the gadget into a div. -->
    <script type="text/javascript">
    var skin = {};
    skin['BORDER_COLOR'] = '#cccccc';
    skin['ENDCAP_BG_COLOR'] = '#e0ecff';
    skin['ENDCAP_TEXT_COLOR'] = '#333333';
    skin['ENDCAP_LINK_COLOR'] = '#0000cc';
    skin['ALTERNATE_BG_COLOR'] = '#ccffff';
    skin['CONTENT_BG_COLOR'] = '#ffccff';
    skin['CONTENT_LINK_COLOR'] = '#0000cc';
    skin['CONTENT_TEXT_COLOR'] = '#333333';
    skin['CONTENT_SECONDARY_LINK_COLOR'] = '#7777cc';
    skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
    skin['CONTENT_HEADLINE_COLOR'] = '#333333';
    skin['NUMBER_ROWS'] = '4';
    google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
    google.friendconnect.container.renderMembersGadget(
    { id: 'xxxxxx',
    site: 'xxxxxx' },
    skin);
    </script>
     
    momrocks, May 11, 2009 IP
  5. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try this, remembering to change the <div id=
    
    echo "<div id='div-xxxxxx' style='width:276px;border:1px solid #cccccc;'></div>";
    echo "<script type='text/javascript'>";
    echo "var skin = {};";
    echo "skin['BORDER_COLOR'] = '#cccccc';";
    echo "skin['ENDCAP_BG_COLOR'] = '#e0ecff';";
    echo "skin['ENDCAP_TEXT_COLOR'] = '#333333';";
    echo "skin['ENDCAP_LINK_COLOR'] = '#0000cc';";
    echo "skin['ALTERNATE_BG_COLOR'] = '#ccffff';";
    echo "skin['CONTENT_BG_COLOR'] = '#ffccff';";
    echo "skin['CONTENT_LINK_COLOR'] = '#0000cc';";
    echo "skin['CONTENT_TEXT_COLOR'] = '#333333';";
    echo "skin['CONTENT_SECONDARY_LINK_COLOR'] = '#7777cc';";
    echo "skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';";
    echo "skin['CONTENT_HEADLINE_COLOR'] = '#333333';";
    echo "skin['NUMBER_ROWS'] = '4';";
    echo "google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);";
    echo "google.friendconnect.container.renderMembersGadget(";
    echo "{ id: 'xxxxxx',";
    echo "site: 'xxxxxx' },";
    echo "skin);";
    echo "</script>";
    PHP:
     
    pixmania, May 11, 2009 IP
  6. i.am.a.pro

    i.am.a.pro Peon

    Messages:
    251
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    echo <<<_HTML_
    <script language="javascript">
    code here
    </scrript>
    _HTML_;

    PHP CODE HERE
    ?>
     
    i.am.a.pro, May 11, 2009 IP
  7. i.am.a.pro

    i.am.a.pro Peon

    Messages:
    251
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    for you it will be

    <?php
    echo <<<_HTML_
    <script type="text/javascript" src="http://www.google.com/friendconnect/script/friendconnect.js"></script>
    <!-- Define the div tag where the gadget will be inserted. -->
    <div id="div-xxxxxx" style="width:276px;border:1px solid #cccccc;"></div>
    <!-- Render the gadget into a div. -->
    <script type="text/javascript">
    var skin = {};
    skin['BORDER_COLOR'] = '#cccccc';
    skin['ENDCAP_BG_COLOR'] = '#e0ecff';
    skin['ENDCAP_TEXT_COLOR'] = '#333333';
    skin['ENDCAP_LINK_COLOR'] = '#0000cc';
    skin['ALTERNATE_BG_COLOR'] = '#ccffff';
    skin['CONTENT_BG_COLOR'] = '#ffccff';
    skin['CONTENT_LINK_COLOR'] = '#0000cc';
    skin['CONTENT_TEXT_COLOR'] = '#333333';
    skin['CONTENT_SECONDARY_LINK_COLOR'] = '#7777cc';
    skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
    skin['CONTENT_HEADLINE_COLOR'] = '#333333';
    skin['NUMBER_ROWS'] = '4';
    google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
    google.friendconnect.container.renderMembersGadget(
    { id: 'xxxxxx',
    site: 'xxxxxx' },
    skin);
    </script>
    _HTML_;


    PHP CODE HERE
    ?>
    It must work
     
    i.am.a.pro, May 11, 2009 IP
  8. somanweb

    somanweb Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi,

    Simple concept

    if you use echo '
    you have to replace ' into \' in the javascript code.

    if you use echo "
    you have to replace all " into \" in the javascript code.

    Soman
     
    somanweb, May 12, 2009 IP
  9. gummyworms

    gummyworms Active Member

    Messages:
    126
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #9
    I suggest you use include 'javascript.html'; just one line. put the javascript in one file with script tags. That way if you site needs fixing you can just worry about one thing at a time.
     
    gummyworms, May 12, 2009 IP
  10. abhishekcis

    abhishekcis Greenhorn

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #10
    Hi
    you can insert javascript in PHP by using the following code

    echo '<script langauage="javascript">';
    echo 'alert("Testing");
    echo '</script>';
     
    abhishekcis, Feb 16, 2011 IP
  11. abhishekcis

    abhishekcis Greenhorn

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #11
    i think that might help you
     
    abhishekcis, Feb 18, 2011 IP