LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   passing php string to javascript function (https://www.linuxquestions.org/questions/programming-9/passing-php-string-to-javascript-function-296049/)

djgerbavore 02-28-2005 07:09 PM

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

coolman0stress 02-28-2005 10:29 PM

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;?>");'

djgerbavore 03-01-2005 11:34 AM

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


All times are GMT -5. The time now is 01:13 PM.