Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

Arrays in Php and Javascript

Javascript coding ..

Moderators: macek, egami, gesf

Arrays in Php and Javascript

Postby drimades » Wed Dec 17, 2003 9:14 am

-------------------------------------------------

How can I use an array (say $ImgArra) of Php in a function Javascript?

-------------------------------------------------
drimades
New php-forum User
New php-forum User
 
Posts: 39
Joined: Wed Oct 29, 2003 2:11 pm

Postby liquedus » Wed Dec 17, 2003 10:10 am

you cant....

why?

Because PHP is processed on the server while JavaScript is processed client side.
liquedus
php-forum Active User
php-forum Active User
 
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada

Re: Arrays in Php and Javascript

Postby swirlee » Wed Dec 17, 2003 2:16 pm

drimades wrote:How can I use an array (say $ImgArra) of Php in a function Javascript?


You're going to have to make PHP echo JavaScript code. Just use foreach() to output each element in the array as a JavaScript array element assignment.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

dynamic javascript :)

Postby ruturajv » Wed Dec 17, 2003 9:08 pm

yeh do this
Code: Select all
<script language=javascript>
<?php
foreach ($arr as $key => $value) {
   echo 'arreg[' . $key . '] = ' . $value . "\n";
}
?>
</script>
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to JavaScript

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.