Solved

Passing a JSON object to a javascript function

Posted on 2014-04-02
3
3,343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

695 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