Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm wondering how to use the a url variable to access JSON variables ?

Status
Not open for further replies.

shiphfwd

Programmer
Mar 10, 2009
2
US
I'm trying to create a new value for a variable to be passed to so_switch function using the url variable. I'm a complete newbie to javascript as a whole. Any help on the matter would be very appreciated.

The link to site its on is
<script type="text/javascript">
//json variables
var speakers = {
edmund_gordon: {
name: "Dr. Edmund Gordon",
attrib: "Richard March Hoe Professor Emeritus and Director of the Institute of Urban and Minority Education, Teachers College, Columbia University",
video: "edmund_gordon",
synopsis: "Perspectives from Dewey and Cremins on the Impact of Arts in Community."
},

maxine_green: {
name: "Dr. Maxine Greene",
attrib: "William F. Russell Professor in the Foundations of Education Professor of Philosophy & Education",
video: "maxine_green",
synopsis: "Test it out people I'm filling the inside of the description with this file. Yay."
},

shirley_brice_heath: {
name: "Dr. Shirley Brice Heath",
attrib: "Margery Bailey Professor of English and Dramatic Literature at Stanford",
video: "shirley_brice_heath",
synopsis: "Test it out people I'm filling the inside of the description with this file. Yay."
},

geoff_canada: {
name: "Geoffrey Canada",
attrib: "President/CEO of The Harlem Children's Zone",
video: "geoff_canada",
synopsis: "Test it out people I'm filling the inside of the description with this file. Yay."
},

linda_frye_burnham: {
name: "Linda Frye Burnham",
attrib: "Richard March Hoe Professor Emeritus and Director of the Institute of Urban and Minority Education, Teachers College, Columbia University",
video: "linda_frye_burnham",
synopsis: "Test it out people I'm filling the inside of the description with this file. Yay."
}
};

//Read url for Variables
var url = String(window.location);
var index = url.indexOf("?");
var data = url.substr(index+1);
var splitted = data.split("=");
var event = splitted[0];
var url_var = splitted[1];

var vid = "speakers."+url_var+".video";
var name = "speakers."+url_var+".name";
var attrib = "speakers."+url_var+".attrib";
var synop = "speakers."+url_var+".synopsis";

// Call for Video Page - JW Video Player
function so_switch( vid , name , attrib , synop ){

var s1 = new SWFObject('assets/jw/player.swf','ply','640','360','9','#000');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('wmode','transparent');
s1.addParam('autostart','true');
s1.addParam('flashvars','file= vid +'.flv&autostart=true' );
s1.write('player');

document.getElementById("info").innerHTML = '<h4>Currently Playing:</h4><p class="name">'+speaker+'</p><span class="attrib">'+attrib+'</em></span>';
document.getElementById("vid_desc").innerHTML = '<h4>Synopisis:</h4><p class="desc">'+synop+'</p>';
}

</script>
 
Can you elaborate what you mean? You already have a 'url' variable... what do you want to do with it? If it's to pass it in to so_switch, simply add it as a new parameter.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hey BillyRayPreachersSon,

I appreciate the speedy response.

With the following I'm trying to insert the url var to create a call to the json variables:

var vid = "speakers."+url_var+".video";
var name = "speakers."+url_var+".name";
var attrib = "speakers."+url_var+".attrib";
var synop = "speakers."+url_var+".synopsis";

I'm trying to get is so that I can get the written information in the top of the full script from my last post to display in so_switch.

example being if ?edmund_gordon is in the url. It should place in to var vid. The result being speakers.edmund_gordon.video which is in the json variable speakers.

edmund_gordon: {
name: "Dr. Edmund Gordon",
attrib: "Richard March Hoe Professor Emeritus and Director of the Institute of Urban and Minority Education, Teachers College, Columbia University",
video: "edmund_gordon",
synopsis: "Perspectives from Dewey and Cremins on the Impact of Arts in Community."
},

My problem is that it's not going to get that value. Instead its printing the string "speakers.edmund_gordon.video".
 
I still don't understand what isn't working.. If I visit your page and click the 'Related Meterial->Video' link, the 'video_init()' function correctly parses and returns 'edmund_gordon'.

Is this not what you want?



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top