...

View Full Version : External JavaScript and PHP



dooballoh
05-06-2006, 02:12 AM
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;

<?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;

<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

dooballoh
05-07-2006, 03:29 PM
Please help with correct syntax;
If php code contains URL;

<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;

echo "document.write(what would be correct syntax of above php code);";
If php code contains FORM;

<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;

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

PremiumBlend
05-13-2006, 05:58 PM
Does it work if you change some of the single quotes to double quotes like this?


echo "document.write('$poll["options"][$i]["vote_option_text"]');";

Ashif
05-13-2006, 08:00 PM
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"]


$poll_options = $poll['options'];

and use


echo "document.write('$poll_options[$i]['vote_option_text']');";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum