/    Sign up×
Community /Pin to ProfileBookmark

including PHP generated array into .js file

Hello,
I am having php generate an array which needs to be accessed by a javascript function in a .js file.

I have tried including the following in the .js file:

document.write(“<SCR” + “IPT LANGUAGE=’JavaScript1.2′ SRC=’New_Arrays4_2.js.php’ TYPE=’text/javascript’></SCR” + “IPT>”);

but this doesn’t seem to work.

I know the output of the php file is ok because when I paste its output into the .js file it works fine.

Thank you for any help.
Patty

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@patty010authorMar 20.2004 — Hello,

I am having php generate an array which needs to be accessed by a javascript function in a .js file.

I have tried including the following in the .js file:

document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='New_Arrays4_2.js.php' TYPE='text/javascript'></SCR" + "IPT>");

but this doesn't seem to work.

I know the output of the php file is ok because when I paste its output into the .js file it works fine.

Thank you for any help.

Patty
Copy linkTweet thisAlerts:
@Khalid_AliMar 20.2004 — you will need to go through the data on php side and generate an array in the js side

$dataArr="";

forwach($data as $key=>$value){

dataArr .= "'".$value."',"

}

make sure that remove an extra comma at the end of the string

var dataArray = new Array(echo $dataArr);

somethin like this will work
Copy linkTweet thisAlerts:
@patty010authorMar 20.2004 — I am sorry , but I am confused about your reply--


the js script is basically a hierarchical menu generator in which you are supposed to manually insert the menu elements.

I generated mine using the php script--it prints out this:


this.item0="Automation Systems"

this.icon_rel0= 0

this.url0='get.php?id=1'

this.item0_0="Automated Carts"

this.icon_rel0_0= 0

this.url0_0='get.php?id=2'

but don't know how to get the js file to access the data--the document .write that I used doesn't seem to work...

thanks,

Patty
Copy linkTweet thisAlerts:
@Khalid_AliMar 20.2004 — I don't think its possible to get what you want from this,post a link where you have this working in the page.So that some one can take look at and see what can be done.
×

Success!

Help @patty010 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...