Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Quickbase and jquery/javascript help

I wonder if someone can help me on a project I am working on for work:

I am trying to modify some jquery/js code in a quickbase app that was build for us. I am trying to use jquery/js to get the client name of a building report we are working on and output it onto a html page. I am able to locate the html for the client name using chrome web developer tool:

    <input type="text" size="40" name="_fid_6" id="_fid_6" onblur="OnBF(this)" onfocus="OnFF(this)" value="Test Client">

In the html file, I see the following jquery/js lines that will write out information about the building we are writing about but I don't know how to call the input for the client name because the variables used to find other building information are not html id's and etc.:

   //Fetch Building Information
    $.get(urlBuilding,function(rec){
        //Get all returned records
        $("record", rec).each(function(j){
            rid  =$(this).find('record_id_').text();
            name  =$(this).find('name').text();
            address  =$(this).find('address').text();
            city  =$(this).find('city').text();
            province  =$(this).find('province').text();
            postal_code  =$(this).find('postal_code').text();
            number_of_units  =$(this).find('number_of_units').text();
            age  =$(this).find('age').text();
            year_of_construction  =$(this).find('year_of_construction').text();
            photo  = $(this).find('photo_embed_tag').text();
            current_rfs = $(this).find('current_rfs').text();

            document.write('<h3>' + name + '</h3>');
            document.write('<table>');
            document.write('<tr><td></td><td>'+photo+'</td></td><td></td></tr>');
            document.write('<tr><td><strong> Address:  </strong></td><td>'+address+'</td><td></td></tr>');
            document.write('<tr><td><strong> City:  </strong></td><td>'+city+'</td></td><td></td></tr>');
            document.write('<tr><td><strong> Province:  </strong></td><td>'+province+'</td></td><td></td></tr>');
            document.write('<tr><td><strong> Postal Code:  </strong></td><td>'+postal_code+'</td></td><td></td></tr>');
            document.write('<tr><td><strong> Units:  </strong></td><td>'+number_of_units+'</td></td><td></td></tr>');
            document.write('<tr><td><strong> Age:  </strong></td><td>'+age+'</td></td><td></td></tr>');
            document.write('<tr><td><strong> Yr of Construction:  </strong></td><td>'+year_of_construction+'</td></td><td></td></tr>');
            document.write('</table>');
        });

After looking at the app more, I was thinking maybe I can't get the client name in the building information section because the client name isn't part of the building... there is a section above the code that has looks like this:

    //Get the current user's client id
    $.get("main?act=API_GetUserInfo",function(xml){
        id = $("user", xml).attr("id");
        email=$("email",xml).text();

        //Set url to query for user's client id
        url="";
        url += "bi3cnb6ep";
        url += "?act=API_DoQuery";
        url += "&query={12.EX.'" + email + "'}&clist=14";
    });

2 Answers

Tough problem! It looks like the name variable is output into an <h3> tag. if you targeted that specific h3 and got the text out and put it in a variable, I would guess you could re-print it somewhere else

The selector might look something like this

namevar = $("(specific path the element you are trying to target) h3").text();

It's a quickbase app and incorporates an ajax request to an xml file.. but I don't really understand all this right now. The name variable in the code right now is actually calling the building name so I can't even guess what the client name variable should be...

ah right. Might want to try this selector then to get the text value of the html form field. This will look for any elements with that specific id, and get the text from those elements

nameval = $('[name="_fid_6"]').text();

Hello, it doesn't work. In order to get the input text of an input field you would use .val() ... so

$('#_fid_6').val(); 

would actually work on google chrome console... but the problem is when I use this and add this into the building info block so

//Fetch Building Information
    $.get(urlBuilding,function(rec){
        $("record", rec).each(function(j){
            client  =$('#_fid_6').val(); 

            document.write('<h3>' + client + '</h3>');
         }
    }

it doesn't work....