mrdhood Posted June 3, 2011 Share Posted June 3, 2011 I have a function that I need accessed two ways. The first way works which is with an ajax json request. it loads name(data) which then does alert(data['user_info']['username']); This works perfect. However I can't figure out how to set it up when a user clicks a span element it alerts their username. An exmaple code that I'm trying to use would be something like this: <span onclick="name('[\'user_info\':[\'username\':\'test\']]');">click</span> This will not work. alert(data); results in "['user_info':['username':'test']]" It won't convert it to an array. using new Array() did not help. (at least the way I tried). Thanks for any help. I did try to search, I'm probably doing some dumb mistake that I'm just overlooking. Quote Link to comment https://forums.phpfreaks.com/topic/238291-array-as-function-paramater/ Share on other sites More sharing options...
Adam Posted June 3, 2011 Share Posted June 3, 2011 You're passing the array as a string literal - remove the quotes around it. Quote Link to comment https://forums.phpfreaks.com/topic/238291-array-as-function-paramater/#findComment-1224590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.