Dynamically Generating Table Using XML
Jan 6, 2011
I am in the process of writing a script that will dynamically generate a table using javascript and XML. I can get all of my data to feed in with no problem but am getting hung up on a few small syntax issues. Basically I need to assign a unique id equal to [i] (instead of id="answerDiv", in bold below) so that when calling showHide() it will show/hide one specific div.
Current Table Script
Code:
//table 2
document.write("<table id='tbl2' cellpadding='0' cellspacing='0' border='0' style='display: none; width:236px;'>");
var x=xmlDoc.getElementsByTagName("feature");
for (i=0;i<x.length;i++) {
document.write("<tr><td class='eventDate'>");document.write(x[i].getElementsByTagName("question")[0].childNodes[0].nodeValue);
document.write("</td><td class='eventText'>");
document.write(x[i].getElementsByTagName("content")[0].childNodes[0].nodeValue);
document.write('<a href="#" class="redLink triviaAnswer" onclick="showHide();">click for answer</a><br><br>
<div id="answerDiv" style="display:none">');
document.write(x[i].getElementsByTagName("answer")[0].childNodes[0].nodeValue);
document.write('</div></td></tr><tr><td colspan="3"><div class="tabs_hr"></div></td></tr>');
} document.write("</table>");
Show/Hide Function
Code:
function showHide(){
var answer = document.getElementById('answerDiv');
if(document.getElementById('answerDiv').style.display == 'none') {
answer.style.display = "block";
} else {
answer.style.display = "none";
} }
View 1 Replies
ADVERTISEMENT
Jun 9, 2005
I want to display a 'preview' image for a file upload field. I assigned a function to the onChanged event for the file input that gets the value of the input text field, does some minor regex to fix the string, and then creates a new 'img' tag element and assigns the fixed string as the img's src: Code:
View 2 Replies
View Related
Feb 16, 2010
I am doing a project where I would like to be able to generate a series of variable names dynamically in the following example
var paper1 = new Raphael('img1', 500, 500);
c1 = paper1.rect(0, 0, 50, 20, 5);
var paper2 = new Raphael('img2', 500, 500);
c2 = paper2.rect(0, 0, 50, 20, 5);
would like to use a loop to increment names
for (i=0;i<=5;i++)
[Code]...
View 4 Replies
View Related
Nov 16, 2010
I'm almost finished with this app for XUL / HTML Table Generation, and i have a really strange problem...The HTML strings in the Arrays can be changed, and the HTML file saved, and the HTML page reloaded, and the changes will render.However, i have one array, no matter what i change the HTML strings to, it refuses to render the changes made to the HTML strings.It's quite confusing...the array in question is
// Humidor InnerHTML
HumidorInnerHTML[0] = "<img src='NoImage.gif' style='height:100px; width:100px;'>";
HumidorInnerHTML[1] = "<input type='textbox' id='Others_Caption" + HumidorIndex + "'>";
[code].....
View 5 Replies
View Related
Nov 25, 2005
At this point I have been able to add the row. But what I want to do and am having trouble with is alternating the row colour to the dynamically added row element.
Sample of code I am using:
Code:
var tbody = document.getElementById('tableItems');
var row = document.createElement("tr");
var remainder = tbody.rows.length % 2;
if(remainder) {
row.setAttribute("class", "rowLightGreen");
}
var td1 = document.createElement("td");
td1.appendChild(document.createTextNode(qty));
td1.setAttribute("class","qty");
row.appendChild(td1);
tbody.appendChild(row);
One thing that puzzles me, is that even after adding a row the table my table.rows.length still = 0.
Does anyone know how I can determine the appropriate amount of rows so that I can apply the appropriate class?
Or is there just something blatantly wrong in my approach?
View 2 Replies
View Related
May 26, 2010
how I would dynamically add another table once text fields in the existing table is clicked on. So pretty much what I have is a table with 5 textboxes lined up horizontally in the first row along with couple of buttons in the second row. What I want is that once one text box is clicked, another table like the one above is created and appears below that initial table. So this is the inital table that should be replicated on each click:
<table>
<tr>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td><input type="text" ></td>
[Code]...
View 16 Replies
View Related
Dec 8, 2009
$.get("user_dynamic_connect.php",
function(data)
{
[code]....
View 1 Replies
View Related
Jan 29, 2011
I can add rows to a table dynamically. Usually triggered by a mouse click but something I am trouble with is how to get the table to a state with no rows or columns just like it has no contents. do believe I can use this codedocument.getElementById('results').tBodies[0];but I am kind of clueless where to find a complete DOM reference or a manual and don't know the attributes or properties I must use to empty (if it is even possible) a previously created table.
View 5 Replies
View Related
May 7, 2009
Can any one tell me the better and professional way to dynamically add row to an HTML table. Currently I am using insertRow() function.
View 1 Replies
View Related
Feb 15, 2012
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
[code]....
how to add 5 rows dynamically by clicking on add5rows button
View 1 Replies
View Related
Jun 27, 2009
I've got 2 div's and the first one has a form in it.I want to create a table with the results of the form results in the second div. It currently erases the page to create the table
I don't use js too much, but for this job, I need to use it
View 4 Replies
View Related
Jun 26, 2002
can a table width be set dynamically with javascript by referencing the users browser window dimensions or the users video settings? ie: if the user video is set 1280 or less, then the table width is 75%. if the video is above 1280 then the table is 800 pixels.
it may not be a good thing to do, but i like percentages on tables except with large display settings. is it too much overhead?
another thought: would it be easier to implement server side with asp/vbscript?
View 2 Replies
View Related
Dec 6, 2002
I'm trying to produce a page with a form on it which is formatted using a table. In the middle is a row which has search parameters in it. What I want to do is to put a drop-down on the left which defaults to "End" but if the user selects another option ("And" or "Or") then I want to insert another row immediately below (which has a drop-down on the right.....) I know I can use the onchange() event to fire off some script, but how do I insert the row into the table?
View 9 Replies
View Related
Aug 5, 2010
I have a code below where I have a table. I am adding rows dunamically on click of Add button where as If the user adds extra rows then the extra row must be deleted on press of the delete image at the last corner of the table.
<div style="display:block; float:left; width: 480px;">
<table border="0" cellpadding="1" cellspacing="0" id="tblInterface">
<thead>[code]......
View 3 Replies
View Related
Nov 27, 2010
I want this script to say "Your roster is empty" after names have been added using the submit button and then removed via the remove button.
Been staring at this for two hours now.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
[Code]....
View 6 Replies
View Related
Aug 16, 2010
I want to create a table dynamically. Here is the working code.[code]This table is always left alignment.Suppose I create another table which has 3x3 cells.Now I want to insert the first 2x2 table into the middle cell of the second table.I am not sure how to get the position of the cells and how to change the javascript code?
View 3 Replies
View Related
Jul 23, 2005
I am just starting to use the DOM to do some more advanced
javascripting so please be patient with my question if it is an
ignorant question.
I would like to use the DOM to dynamically create an html table via
javascript. While that table is being dynamically created in a
javascript function I would like to dynamically insert text and a
hyperlink with an image into each cell.
I got pretty far on my own. I was able to dynamically create a table
and insert a string into each cell. However, I was not able to use
the DOM to insert a hyperlink into each cell. I tried adding it as a
new text node and got the text of a link rather then a link. I then
tried adding and setting an anchor element but I got nothing. Code:
View 5 Replies
View Related
Jul 13, 2011
I want to add rows and columns on click. So, i have a table with columns and rows and I had a add and remove button. So I want the user to be able to add/remove more rows if they have multiple inputs/outputs.So what I want is when the user clicks on add.png, I want another row of Input and Description to appear underneath the current oneHere is my code..
<img src="images/add.png" width="15" height="15" align="right" >
<div class="open">
<table width="200" border="0">
[code]....
View 2 Replies
View Related
Apr 5, 2007
Does anyone know how to Dynamically add new rows to a table through plain javascript.
I tried changing the InnerHTML with getelementbyid() already and that doesn't work.
View 3 Replies
View Related
Mar 23, 2010
I am building a schedule web page and before I just had it use plain static HTML and CSS to control the styling. I wrote some javascript that goes through the table's rows, then cells (double for loop), and if the cells innerHTML == "" then the style class is changed. I do have some working code, however it only works in IE. Here's a copy of the script:
<script type="text/javascript">
for (var i = 0; i < document.getElementById('table').rows.length; i ++)
for (var j = 0; j < document.getElementById('table').rows(i).cells.length; j ++)
if (document.getElementById('table').rows(i).cells(j).innerHTML == "")
[Code].....
View 1 Replies
View Related
Feb 17, 2005
ok basically i want to move two rows in a table.
for example i have the table:
1 name1 address1
2 name2 address2
3 name3 address3
4 name4 address4
and i'd like a javascript function to which i could pass a line number, a destination number, and it would then reorganize the table accordingly.
example: rebuildtable(4,2) would result in:
1 name1 address1
4 name4 address4
2 name2 address2
3 name3 address3
and rebuildtable(1,4) in:
2 name2 address2
3 name3 address3
4 name4 address4
1 name1 address1
I have tried a method using innerHTML, I seem to be able to access <tr>s' innerhtml (if i do an alert on them i can see their current status), however when i want to replace one tr with some other html it fails for some reason.
View 1 Replies
View Related
Mar 22, 2010
i am having a table with some rows, which are shown under some categories. how can i dynamically add some rows to the table. there is a '>>' symbol infront of each category names. when i click on that symbol, i want to enlarge this category by adding more no of rows under this. And the symbol must turn to '<<'. when click on this, the reverse thing, ie, remove some rows and shows the initial rows.
View 1 Replies
View Related
Jul 23, 2005
Can someone tell me how to do this if it is possible?
I have a table based web site, and I would like to dynamically change the
text that is shown in a particular cell of a table. I give the cell the
unique ID label1 so I can get a hold of it, and I can get a javascript to
display the data in an alert box (this is just to see if I can access the
text) with:
mycel = document.getElementById('label1');
myceltext = mycel.childNodes.item(0);
currenttext = myceltext.data;
alert(currenttext);
But how do I exchange the text in this cell for something else?
View 5 Replies
View Related
Jul 20, 2005
I've created a table with Table Header and the table may or may not
contain any rows initially.
I've included a .css file in <head> section of my HTML script and I'm creating rows to the table dynamically using JavaScript (using DOM), and the problem is those created bby DOM are not following style sheet rules applicable for table rows and cells. But the
rows created from within HTML script are following style sheet rules. The following is sample which is used to create dynamic row. Code:
View 1 Replies
View Related
Jul 20, 2005
Is there a way to dynamically (e.g. upon onClick) change the bgColor
attribute of a table cell? I tried cell.setAttribute("bgColor",
someColor), where someColor was a string of the form "#RRGGBB",
but nothing happened.
Also, how can I set the mouse cursor to be an arrow when it hovers
over these table cells? (It's an insertion bar now.)
View 5 Replies
View Related
Jul 30, 2010
How do I create html table dynamically?Here is my code:html code:
<div id="dynamicTable">
</div>
jquery code:
[code]....
View 3 Replies
View Related