LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-28-2005, 07:09 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 441

Rep: Reputation: 30
passing php string to javascript function


hello,

i'm trying to pass a php array to a java script function.


first i turn the array into a string:
PHP Code:
<?php
$my_arr 
= Array("one""two""three");
$arr_str implode(','$my_arr);
?>
<--html code -->
<input type = 'radio' name='name' value='value'
onclick = print_php_arr(<?php echo $arr_str ?>)>Radio Button
my question is I get errors when trying to run this. My question is how do i pass a php array to a javascript function??/


thanks,'

djgerbavor3
 
Old 02-28-2005, 10:29 PM   #2
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Don't forget to pass quoted strings to your function as well as have the actual JavaScript function.

Code:
onclick = 'print_php_arr("<?=$arr_str;?>");'

Last edited by coolman0stress; 02-28-2005 at 10:30 PM.
 
Old 03-01-2005, 11:34 AM   #3
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 441

Original Poster
Rep: Reputation: 30
hey thanks, that worked perfectly. you da man

i was getting alittle stressed out because i couldn't figure out how to do it!

thanks again,

djgerbavor3
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 12:08 PM
optimize PHP string function Cedrik Programming 6 08-29-2004 09:07 AM
PHP script/function to get 4-5 words around a keyword in a string(like google) rmanocha Programming 8 07-13-2004 06:19 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
passing a string to a function jkobrien Programming 8 11-05-2003 01:41 PM


All times are GMT -5. The time now is 08:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration