Solved

Passing a JSON object to a javascript function

Posted on 2014-04-02
3
3,136 Views
Last Modified: 2014-04-03
I am trying to pass a JSON object to a function.  For some reason, it's not working and the javascript errors out.

The Error I get is:
SyntaxError: missing ] after element list
http://localhost/javascript/jquery-1.10.2.min.js
Line 4.

I generate the button using this js code:
menu = "<button id=\"mttrmenubtn_"+rowObj.ticket_num+"\" class=\"small blue\" onmouseover=\"vw_showMTTRMenu("+rowObj+");\"><i class=\"icon-large icon-expand\"></i></button>"; 

Open in new window

     

The rowObj is correct and is a JSON object.

When the actual HTML gets generated, it ends up looking like this:
<button id="mttrmenubtn_04CVG" class="small blue" onmouseover="vw_showMTTRMenu([object Object]);">
<i class="icon-large icon-expand"></i></button>

Open in new window


An of course it errors out on the called function.  
How can I pass a reference to the object through this generated code?

thanks
0
Comment
Question by:mamuscia
3 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 39973833
shouldn't there be a comma between object and object within  [ ] ?
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39974656
You can't pass the actual object - you need to pass a reference to it, so when you create your HTML, use something like this:

onmouseover=\"vw_showMTTRMenu(rowObj)\"

Now as long as rowObj exists in your page (probably as a global var), it will get passed into the function
0
 

Author Closing Comment

by:mamuscia
ID: 39974815
Thanks...just using the reference works.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now