Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 6th, 2007, 05:11 PM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default add id tag with setAttribute generates escape char

I am having some strange problems with a script, but am pretty sure that there is an obvious answer! The function below add a new row to a table.

The problem is that i can't access the new ID tag later in my code. I'm calling the function like so:

        AddTableRow('tb_test', 'vendas' + arrVendas.length, new Array codigo_barras,"","", "", "", "", "", ""));

so i expect my new row to look like:
<TR ID="VENDAS1"></TR>

but it actually end up like so:
<TR ID=\"VENDAS1\"></TR>


Any ideas on how i can either set the attribute without the strage escape characters or how to access the ID if the characters remain?

Thanks for any help!!

Here's my function:


function AddTableRow(TableID, rowID, rowContent)
    {

    var table = document.getElementById(TableID);
    var columns = table.childNodes(0).getElementsByTagName('TD');
    var rows = table.getElementsByTagName('TR').length;
    //alert('rows: ' + rows);

    //criar nova row
    var tr = document.createElement('TR');
    //criar colunas da row
    for(var i=0; i<columns.length; i++)
        {
        var td = document.createElement('TD');
        try
            {
            td.innerHTML = rowContent[i];
            }
            catch(err)
            {
            }
        tr.appendChild(td);
        }

    tr.setAttribute('ID', rowID);
    table.appendChild(tr);
    }
 
Old June 6th, 2007, 05:18 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I'm not sure what's working but HTMl tables can be tricky. You are using non-standard methods for dealing with them, you should be using insertRow() and insertCell(), details of which are available on the W3C web site.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP Add New Record and Get ID omninewt Classic ASP Databases 5 April 10th, 2008 12:20 PM
Escape char for '-' mattastic Access 1 October 6th, 2005 03:27 PM
ASP program How to add new ID for new record kinshuk SQL Server ASP 3 March 21st, 2005 02:43 PM
How to add a javascript within a iframe's tag ? muklee Javascript How-To 2 September 28th, 2004 04:25 AM
Suggestion... escape of [ char in messages nikolai Forum and Wrox.com Feedback 6 September 22nd, 2003 01:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.