Wrox Programmer Forums
|
BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers by Nicholas C. Zakas; ISBN: 9780764579080
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 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 November 2nd, 2011, 06:35 AM
Registered User
 
Join Date: Jan 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add attributes to html table using javascript?

I want to create a html table dynamically using javascript.
here the element name and attributes will be passed to the function as shown below.

Code:

Code:
function createhtml(elementname,attr)
{
for(j=0;j<attrs.length;j++)
                        {                            
                             attr1=attr1.split("=")  
                               atr=attr1[0];
//first method
 window['o' + elementname].setAttribute(atr, attr1[1]);  
 //second method                    
 var e=document.getElementById(elementnode)
e. window[atr]= attr1[1]  }  
                            }

here window['o' + elementname] is the element to which the attributes needs to be set.
atr is the name of attribute and attr1[1] is the value. To create an attribute dynamically which is in bold as shown in the code above.
here instead of giving
Code:

Code:
e. style.width= attr1[1]

i want to write
Code:
e.'the variable name'=attr1[1]
in both methods that i mentioned in my code null value error occurred.
how to achieve this?

Last edited by ammu86; November 2nd, 2011 at 07:30 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Display HTML Attributes from XML Attributes rangeshram XSLT 3 March 27th, 2010 01:14 PM
this.attributes.add not working millerthegorilla SharePoint Development 1 June 17th, 2008 03:44 AM
Transform html table to add ids/headers using xsl kapy_kal XSLT 2 February 21st, 2007 10:12 AM
Calling Javascript Function With Attributes.Add OutCaster ASP.NET 1.0 and 1.1 Basics 1 January 27th, 2006 09:53 PM





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