JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 2nd, 2011, 03:44 AM
ammu ammu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 ammu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 33 sec
Reputation Power: 0
Need Help Debugging Script/Error in Script - 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:
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 i tried several methods to create dynamically an attribute which is in bold in the code above.
instead of giving
Code:
e. style.width= attr1[1]

i want to write e.'the variable name'=attr1[1]
how to achieve this?

Reply With Quote
  #2  
Old January 1st, 2013, 04:46 PM
Kravvitz Kravvitz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: USA
Posts: 140 Kravvitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 23 m 39 sec
Reputation Power: 9
You're close. You do want to use "array notation" instead of "dot notation" for that segment, but the "window" object has nothing to do with it.
Code:
var e=document.getElementById(elementname);
e[atr]= attr1[1];

P.S. While semicolons at the end of lines are optional in many cases, it's best practice to include them anyway.
__________________
Spreading knowledge, one newbie at a time.

Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

Check out my blog.

Reply With Quote
  #3  
Old January 7th, 2013, 07:15 AM
Rkjobdft Rkjobdft is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 Rkjobdft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 15 sec
Reputation Power: 0
it's best practice to include them anyway.


Reply With Quote
  #4  
Old January 15th, 2013, 01:54 AM
coxodoina coxodoina is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 coxodoina User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 56 sec
Reputation Power: 0
I want to create a html table dynamically using javascript.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Need Help Debugging Script/Error in Script - How to add attributes to html table using javascript?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap