Need help with Javascript and PHP

Discussion in 'PHP' started by Alvin, Apr 4, 2007.

  1. #1
    Hello Freinds,

    I want to echo this javascript on php page.


    i need to echo this.
    can some one help me please. :)

    thanks
    Alvin
     
    Alvin, Apr 4, 2007 IP
  2. Andy Peters

    Andy Peters Peon

    Messages:
    430
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?
    echo "
    &lt;script&gt;<br />
    image_id = &quot;123456&quot;<br />
    image_src=&quot;./$path&quot; . $id . &quot;;<br />
    &lt;/script&gt;<br />
    &lt;script src=&quot;http://www.mysite.com/code.js&quot;&gt;&lt;/script&gt;<br />
    &lt;noscript&gt;&lt;/noscript&gt;"; ?>

    or <?

    echo "<script>
    image_id = \"123456\"
    image_src=\"./$path" . $id . \";
    </script>
    <script src=\"http://www.mysite.com/code.js\"></script>
    <noscript></noscript>";?>

    First one will display the code in browser, second one will execute the javascript.
     
    Andy Peters, Apr 4, 2007 IP
    Alvin likes this.
  3. Alvin

    Alvin Notable Member

    Messages:
    2,076
    Likes Received:
    164
    Best Answers:
    0
    Trophy Points:
    210
    #3
    did not work. Its displaying plain html.

    can I add you on msn if you can help me?
     
    Alvin, Apr 4, 2007 IP
  4. Felu

    Felu Peon

    Messages:
    1,680
    Likes Received:
    124
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this
    <?php
    echo "<script>
    image_id = \"123456\"
    image_src=\"./$path".$id.";
    </script>
    <script src=\"http://www.mysite.com/code.js\"></script>
    <noscript></noscript>";
    ?>
    Code (markup):
     
    Felu, Apr 4, 2007 IP
  5. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #5
    
    echo '<script>
    image_id = "123456"
    image_src= "./$path' . $id . '";
    </script>
    <script src="http://www.mysite.com/code.js"></script>
    <noscript></noscript>';
    
    PHP:
    That should work :)
     
    Louis11, Apr 4, 2007 IP
  6. degy

    degy Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i really doubt this will work i'll send you my solution in few mins i have to find it ;)
     
    degy, Apr 5, 2007 IP
  7. degy

    degy Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    try this but i really don't know if it'll change anything but i would give it a try ;)

    $foo='<script>
    image_id = "123456"
    image_src= "./$path' . $id . '";
    </script>
    <script src="http://www.mysite.com/code.js"></script>
    <noscript></noscript>';

    echo '
    <script>
    eval('.$foo.');
    </script>';
     
    degy, Apr 5, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    ^^ $path is between single quotes and won't be parsed. Then why on earth are you eval'ing the JavaScript? And eval() won't work with the <script> tags inside...

    Try this.
    
    <?php
    
    echo '<script type="text/javascript">
    image_id = "123456";
    image_src= "./' . $path . $id . '";
    </script>
    <script type="text/javascript" src="http://www.mysite.com/code.js"></script>
    <noscript></noscript>';
    
    ?>
    
    
    PHP:
     
    nico_swd, Apr 5, 2007 IP
  9. degy

    degy Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    well i had few cases when js didn't work when parsed with php. I used eval and then it worked :D Oh yeah and yeah it should be without script tags
     
    degy, Apr 5, 2007 IP