#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2016
    Posts
    21
    Rep Power
    0

    JQuery .Load writing to wrong column


    I have a table with two columns. One is the part number and the second is the description of the product.

    I am writing a jquery statement for each row in the table the .load function looks up the part number in column 1 and writes the product description to column 2.

    Column1 has an id of the part number ie. 92K002
    Column 2 has an of 'x' and the part number ie. x92K002 I have done this to ensure I always have a unique id.

    I have the following code

    Code:
    $(document).ready(function(){
            $('tbody > tr > td > pre').each(function() {
    			//alert( '#c'+$(this).text())
    			$('#c') + $(this ).load('table_ajax.asp?pn=' + $(this).text());
    			});
        });
    The code returns the product description, but overwrite the part number in colum 1.

    I am guessing it has something to do with this line
    Code:
    $('#c') + $(this ).load('table_ajax.asp?pn=' + $(this).text());
    .

    If anyone could help that would be great.
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,271
    Rep Power
    4193
    $('#c') finds the element with id="c", and essentially does nothing with it
    $(this) refers to the element you selected, which would be your <pre> tag with the part number
    .load(...) then tells jQuery to load the contents of the URL into that <pre> tag, thus overwriting your part number.

    Your .load method needs to be called on your other column element, not on $(this). I'm guessing $('#c') + is your attempt at referring to the element with an id that starts with c followed by that same id as the current cell. If that's the case, you need to generate your ID string first, then pass that into your jQuery constructor. You'd get the current elements id using the .attr('id') method.

    Code:
    var otherColumnId = '#c' + $(this).attr('id');
    
    $(otherColumnId).load('table_ajax.asp?pn=' + $(this).text());

    Comments on this post

    • jongee agrees
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2016
    Posts
    21
    Rep Power
    0
    Your code works a treat.

IMN logo majestic logo threadwatch logo seochat tools logo