Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

Rep: Reputation: 30
passing php string to javascript function


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

first i turn the array into a string:
PHP Code:
= 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??/


Old 02-28-2005, 10:29 PM   #2
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.

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
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

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,



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

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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:56 AM.

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