Jump to content

array as function paramater


mrdhood

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.