...

View Full Version : External JavaScript and PHP



dooballoh
05-05-2006, 01:32 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 am stuck with these codes;
php codes;

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

felgall
05-05-2006, 07:45 AM
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.

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

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

But then problem is as my first post.
Help please.

Thank you in advance



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum