Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

javascript Table Updating

  • 23-06-2009 11:52am
    #1
    Registered Users Posts: 500 ✭✭✭


    I have a table in html with a lot of rows. When something happens - I change the data in those rows with javascript.

    However this involves code like so in my javascript

    output += "<tr>"
    output += "<td>"+this.fields.firstname+"</td>"
    output += "<td>"+this.fields.surname+"</td>"
    output += "<td><a href=\"browse/"+this.fields.test+"</a></td>
    output += "<td><img src='/images/xxx.gif'/>"+this.fields.phone+"</td>"
    output += "</tr>"

    However, I dont want to hardcode any html like <"tr"> in my javascript - how can i do it?

    Please help


Comments

  • Moderators, Category Moderators, Motoring & Transport Moderators Posts: 21,238 CMod ✭✭✭✭Eoin


    You can add rows to a table using the DOM, rather than hard-coding any tags.

    Check this out:
    http://www.mredkj.com/tutorials/tableaddrow.html


  • Registered Users Posts: 500 ✭✭✭warrenaldo


    Thanks Eoin,

    Didnt think I would ever get a reply.
    I have been working on it since I posted and came up with something using Jquery.

    var row = $("#tableid tr:last").clone()
    $("td:eq(0)", row).text(this.fields.firstname);
    $("td:eq(1)", row).text(this.fields.surname);

    It works well.


  • Moderators, Category Moderators, Motoring & Transport Moderators Posts: 21,238 CMod ✭✭✭✭Eoin


    Ah cool - seems to be pretty tidy code.


Advertisement