473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to set attributes in dynamically creating table structure using javascript?

6
Im developing a script for dynamically creating html table structure so that from the input that has been given to the function it will fetch the values one by one and will create the structure. My problem is i want to add attributes to the elements created. sample code attached.
Expand|Select|Wrap|Line Numbers
  1. with( window['o' + elementname]){
  2. for(j=0;j<attrs.length;j++)
  3. {
  4. if(attrs[j].indexOf("=")!=-1){
  5. var attr1={}
  6. attr1=attrs[j]
  7. attr1=attr1.split("=")
  8.  window[attr1[0]]=attr1[1];
  9.  }
  10.  }}
  11.  
here the element name will be get from the parameters passed to the function. i want to verify whether the line in bold is correct or not coz the id is not updated in output.
Nov 1 '11 #1
3 2352
acoder
16,027 Expert Mod 8TB
Can you not use setAttribute()? Can you post a sample input?
Nov 3 '11 #2
ammu86
6
The parameter that i passed to the function will be in the below format.
var attr = {node:"<tr>,id=tr1$<td>,id=td1,colspan:2,style.wid th=100%$<div>,id=oWaiter,name=oWaiter,style=positi on:relative,border:1px gray solid,overflow:hidden,width:200px,height:15px,back ground-color:#FFF;"}


for eg: when the value style.width=100% passed to parameter it should assign to the element. If i use setattributes instead of 'style=position:relative' it will return 'style=position=relative'. which is not correct.
Nov 3 '11 #3
acoder
16,027 Expert Mod 8TB
Interesting and strange. Any particular reason why it's in this format? Could you not use XML or JSON or at least make it easier to use? That's not to say it's impossible or even difficult, but it just adds complexity where it's not required.

The $ character seems to be the separator. Once you split on that, you can split again on the comma to get the tag, e.g. <tr>. Then you can split again on the = to get attribute/value pairs.

Unfortunately, it seems there's some inconsistency,e.g. "colspan:2" instead of "colspan=2".
Nov 9 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Frederik S | last post by:
Hello, I'm making a nice little login box in Javascript but having problems Posting the value inside a textfield. In a nutshell: I have a function: function getPostData (value)
2
by: SMBR via AccessMonster.com | last post by:
I am not completely new to Access, but I have run into a road block in trying to normalize my database. I am not sure if I am using the correct structure here. I have tried to post a few times...
1
by: Karim | last post by:
I have a form built into an html table. One of the form elements is an asp.net dropdownlist. For some options in the listbox, I want to insert a new table row under the listbox to grab some more...
4
by: Grigs | last post by:
Hello, I have an asp:table on my page. I am, after a button gets clicked, programmatically adding rows and their cells. Using the Cell.Text = to put the value in the cell. I then have another...
1
by: gaya3 | last post by:
Hi, How to insert row in table using javascript when some event occurs in html? -Hamsa
1
by: stepby | last post by:
Dear All, I want to make a function to add a row in the table by click the add button and delete the row by choosing the checkbox at the first of the row and click the delete button. can it...
5
by: phub11 | last post by:
Hi all, I've not had much luck getting any responses from my previous posts, but managed to figure stuff out. Now I'm really stuck! Any help at all would be great.... I'd like to use a SELECT...
1
by: Nelson Joseph | last post by:
Hai all, I would like to create an XML file using JavaScript. Is it possible? Please tell me how can we create? Thanks in advance. - Nelson
7
by: ms026057 | last post by:
I Have a File a.html file Content <html> <body> <table> <tr><td id="table1">this content from b.html</td></tr> </table> </body> <html>
1
by: visweswaran2830 | last post by:
Hi, I want to insert href into tabel cell using javascript. Note should support all browser. I know to insert, but it support only in IE, I checked in firefox, it does not support so please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.