Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
05-13-2013, 11:49 PM #1
- Join Date
- May 2013
- Thanked 0 Times in 0 Posts
how to pass an variable thats an array to a function
I am having trouble passing an array to a java script function. here is my code.
Its weird I created another variable called test and set it equal to the array($test = "$row"; )
it worked, but does not show the word. What it does is just shows one of the letters if I do test in ....american('$test')... why wont it show the whole word when its just $test, and why nothing shows with $row
$test = "$row"; echo "<button onclick=american('$row')>$row</button><br />";
05-14-2013, 12:22 AM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,668 Times in 2,637 Posts
$test doesn't have any value in the code you have posted here. Assuming $row is a string within an array of $row, then using $test would be the first letter of the value in $row.
$row = array('This is a string');
$test = $row;
print $test; //T
As for the JS, the only thing I can see being a problem PHP wise is if your string contains a ' within it which would damage the request for the american function call. Otherwise, assuming that $row is a valid array, everything looks fine. You can check your output HTML source to see what's in the <button> value and onclick attribute.PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');
Users who have thanked Fou-Lu for this post: