Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    External JavaScript and PHP

    Hello.

    I am using phpBB and wanted to display latest poll in phpBB to my home page.
    My home page is html extention and want to use java to call it and display it.

    I am stuck with these codes;
    php codes;
    Code:
    <? php
    SOME, SOME....
    {
    echo "document.write('$poll['options'][$i]['vote_option_text']');";
    } ?>
    My question is that, if ['options'] then will not print anything, if I remove ' ' then print something. However if I put all 4 items ('$poll['options'][$i]['vote_option_text']');"; without ' ' inside of [ ] it will print like;
    Array[0][vote_option_text]Array[1][vote_option_text]Array[2][vote_option_text]Array[3][vote_option_text]Array[4][vote_option_text]Array[5][vote_option_text]
    What is correct syntax?
    Please help!!!

    Thank you in advance

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    If the PHP is in an external Javascript file you need to specify the scipt tag as

    <script type="text/javascript" src="myfile.php"></script>

    so that it gets parsed as PHP on the server first before being run as Javascript by the browser.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ooops, I may be in wrong forum.

    Thank you very much 'felgall'.

    I may didn't make it clear.
    I've already did that part in my html page.
    Also I changed my php file as below;
    Code:
    <?php 
    Header("content-type: application/x-javascript"); 
    
    function myfunction() 
    { 
    return $something; 
    } 
    
    $some_variable=$something; 
    
    echo "document.write('$poll['options'][$i]['vote_option_text']');";
    
    ?>
    When called remotely by javaScript, I included this in my html page as below;
    Code:
    <script> type="text/javascript" src="http://www.mydomain.com/myfile.php"></script>
    But then problem is as my first post.
    Help please.

    Thank you in advance


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •