Solved

How to source value in javascript?

Posted on 2012-04-12
3
178 Views
Last Modified: 2012-04-12
If I have something like:

window.gaikai = {
                        emailToken: 'KHn5rB8007' // token
                gameCode: 'my_g_origin',
                messageCallback: function(obj) {
                              var currGame = 'my_g_origin';
                    // Log all messages to browser console, if available
                    if (console && typeof console.log === 'function') {
                        console.log(obj.message);
                    }
                    if (obj.message === 'clickPlayNow') {
                                 var autoPlay =  location.href.indexOf("gaikaiInstantPlay") > 0;
                                 if(autoPlay){currGame = currGame + '_autoPlay';}
                                 setOmniValues('','o','clickPlayNow','','e66='+currGame,'ev91',0,'','')
                       
                    }
                 }
            };

Is there a way I can source the value of gameCode: 'my_g_origin' in the javascript without reassigning it as I'm doing (var currGame = 'my_g_origin';)? Is it window.gaikai.gameCode?


Thanks!
0
Comment
Question by:894359
  • 2
3 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37840612
Yes but it looks like you missing a comma after this line:

 emailToken: 'KHn5rB8007'

Should be

 emailToken: 'KHn5rB8007',
0
 

Author Comment

by:894359
ID: 37840621
Yeah I caught that! ;0) Thanks! So how do I reference it in my js? None of the below work?

alert(gaikai.gameCode);
alert(gaikai.gameCode.value);
alert(window.gaikai.gameCode);
alert(window.gaikai.gameCode.value);
0
 
LVL 23

Accepted Solution

by:
basicinstinct earned 500 total points
ID: 37840630
This is the right one:
 alert(window.gaikai.gameCode);

If it doesn't work you got a problem somewhere else in your script.

you need to advance beyond alert debugging. press f12 in your browser and start using the console in the developer tools
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 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