Getting record by name

Hey guys,

I am currently working on a little script that checks for the name and then retrieves the appropriate data from either XML or JSON.
Below is how far I have gotten thus far… the script works to retrieve some records, problem is its only able to get the first record because there is no check yet which one it wants.

This where it executes the actions when clicking on any of the dd/dt list options:


$(".List dd").live("click",function(){
		var Name = $(this).attr('class');
		changeHeader(Name);
		changeDesc(Name);
	});	

And once clicked it retrieves the data, but im not sure what the right syntax is to use the “+a+” in the example below.

		
//Change Desc
		function changeDesc(d) {
		$("#list dl a").click(function(event){
          $.getJSON('myDesc.json', function(desc) {
             $('#info').html('<h1>  ' + "+a+".desc.title  + '</h1>');
             $('#info').append('<p> ' + "+a+".desc.description + '</p>');
          });
      });
}

Help would be much appreciated, thanks in advance,
Mehk

Can’t figure out what’s that “a” you’re trying to put there? Is it a variable or just a letter “a”?

In the first example Name = $(this).attr(‘class’);
and are both changeHeader(Name); and changeDesc(Name); appointed then in the second example the “a” stands for the “Name” which works in all my examples just dont know the right syntax to put it in,

('<h1> ’ + “+a+”.desc.title + ‘</h1>’);
Does not work because the syntax is invalid.

You got there

function changeDesc(d)

So you should use “d” variable in that particular function.

If you want to just concatenate (prepend) that variable with title and description, here is the code:

//Change Desc
function changeDesc(d) {
	$("#list dl a").click(function(event){
		$.getJSON('myDesc.json', function(desc) {
			$('#info').html('<h1>  '+ d + desc.title +'</h1>');
			$('#info').append('<p> '+ d + desc.description +'</p>');
		});
	});
}

If you wanted to put a dot between, then it should look like that:

//Change Desc
function changeDesc(d) {
	$("#list dl a").click(function(event){
		$.getJSON('myDesc.json', function(desc) {
			$('#info').html('<h1>  '+ d +'.'+ desc.title +'</h1>');
			$('#info').append('<p> '+ d +'.'+ desc.description +'</p>');
		});
	});
}

Concatenating strings in JS:

var [B]foo[/B] = "foo";
var bar = [B]foo[/B] +'baz'+ [B]foo[/B] +'qux'; // [B]foo[/B]baz[B]foo[/B]qux

Thanks! thats pretty close to what im trying to achieve:)
, except it now just appends the data behind “d” which is a class name, while im trying to get the class name and then find the records description and title.

so d.description and d.title dont work in its current state.