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 4 of 4
  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 have php page changed to;
    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>
    The problem is that, if I put '$poll['options']' then will not print anything, if I remove ' '(semi qoute) inside of [ ] then print something. However if I put all 4 items ('$poll['options'][$i]['vote_option_text']');"; without ' '(semi qoute) 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? or what did I do wrong?
    Please help.

    Thank you in advance

  • #2
    New Coder
    Join Date
    Jan 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please help with correct syntax;
    If php code contains URL;
    Code:
    <span class="gensmall"><a href="<?php echo append_sid($phpbb_root_path . 'viewtopic.php?t=' . $poll['topic_id'] . '&amp;vote=viewresult'); ?>"><?php echo $lang['View_results']; ?></a></span>
    then, what is correct syntax to javascript?
    Example;
    Code:
    echo "document.write(what would be correct syntax of above php code);";
    If php code contains FORM;
    Code:
    <form method="post" action="<?php echo append_sid($phpbb_root_path . 'posting.php?t=' . $poll['topic_id']); ?>">
    then, what is correct syntax to javascript?
    Example;
    Code:
    echo "document.write(what would be correct syntax of above php code);";
    These things really drive me crazy.
    Please please help me.

    Thank you in advance

  • #3
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Does it work if you change some of the single quotes to double quotes like this?

    Code:
    echo "document.write('$poll["options"][$i]["vote_option_text"]');";
    My Website: DumpsterDoggy

  • #4
    New Coder
    Join Date
    Apr 2004
    Location
    Fsd / PK
    Posts
    68
    Thanks
    11
    Thanked 0 Times in 0 Posts
    if u have started with the Double qoutes, then u can not used the double qoutes inside, u haev to work with single qoute..
    do like this
    make a variable to store the $poll["options"]
    Code:
    $poll_options = $poll['options'];
    and use
    Code:
    echo "document.write('$poll_options[$i]['vote_option_text']');";


  •  

    Posting Permissions

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