SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    Code:
    $(".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.
    Code:
    		
    //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

  2. #2
    SitePoint Member
    Join Date
    Nov 2010
    Location
    Rumia
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't figure out what's that "a" you're trying to put there? Is it a variable or just a letter "a"?

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MattCA View Post
    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.

  4. #4
    SitePoint Member
    Join Date
    Nov 2010
    Location
    Rumia
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You got there
    Code:
    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:
    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:
    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>');
    		});
    	});
    }

    Concatenating strings in JS:
    Code:
    var foo = "foo";
    var bar = foo +'baz'+ foo +'qux'; // foobazfooqux

  5. #5
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •