Anyone help me to add javascript to index.php file?

by 6 replies
8
This is script I want to add, like this
<?php echo '<script type="text/javascript" src="http://forms.example.com/form/86/1985011386.js"></script>';

It works. But I want to add multiple script to my php files.
It is not working when I put like this,

<?php echo '<script type="text/javascript" src="http://forms.example.com/form/86/1985011386.js"></script>';
'<script type="text/javascript" src="http://forms.example.com/form/86/1985011386.js"></script>';

How to put two script?? Help me guys.

Thanks.
#programming #add #file #indexphp #javascript
  • I think I see the problem. You have the echo on the first script, then you terminate the command with the ; The second script does not have an echo command. If you put "echo" in front of the second script it will work.

    <?php echo '<script type="text/javascript" src="http://forms.example.com/form/86/1985011386.js"></script>';
    echo '<script type="text/javascript" src="http://forms.example.com/form/86/1985011386.js"></script>';
    • [1] reply
    • You can break out of php and then output the javascript:

      PHP Code:
      <?php

      // php stuff
      ?><script type="text/javascript" src="http://forms.example.com/form/86/1985011386.js"></script>
      <script type="text/javascript" src="http://forms.example.com/form/86/1985011386.js"></script>
      <?php 

      // more php stuff

      ?>
      Or, if you really want to echo it out, you have to escape the quotes, like this:


      Sorry for posting an image, but the PHP parser on this forum strips characters crucial to the code.
  • Why do you believe that you need to echo the script to put it on a PHP page? PHP allows you to break from PHP and just enter normal HTML as you would as if it weren't a PHP page:
    PHP Code:
    <?php
    //do server scripting here
    ?>
    <!--HTML-->
    <?php
    //more server scripting here
    ?>
    • [1] reply
    • As I mentioned above, the script is working well for the first script. Then when I try to add more script, then it stop working. My question is how to add more script to the php page. Yes! Of course it need "echo" .If I did not put this, it will not works.

      Thanks.
      • [1] reply
  • Banned
    [DELETED]

Next Topics on Trending Feed