| | |
using javascript to dynamically add to existing html table
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jan 2007
Posts: 13
Reputation:
Solved Threads: 0
I have been working on a questionnaire results page which takes the values from the questionaire on the previous page, calculates a score then plots their results on a grid. this all works fine, what i am a little baffled about however is, how do i dynamically add table rows/cells to an already existing table? if i use document.print() it just overwrites all the existing html etc.
here is the function i currently have to output the information:
function summary(){
var resultArr = new Array();
for(i=0;i<14;i++){
if(newValArr[i]==100){
resultArr[i] = "Strongly Agree";
}
if(newValArr[i]==75){
resultArr[i] = "Agree";
}
else if(newValArr[i]==50){
resultArr[i] = "Disagree"
}
else if(newValArr[i]==25){
resultArr[i] = "Strongly Disagree"
}
else if(newValArr[i]==0){
resultArr[i] = "Not my job";
}
if(i==13){
//alert('broken out of strongly agree loop');
}
}
for(i=14;i<27;i++){
if(newValArr[i]==100){
resultArr[i] = "Always";
}
if(newValArr[i]==75){
resultArr[i] = "Usually";
}
else if(newValArr[i]==50){
resultArr[i] = "Occasionally"
}
else if(newValArr[i]==25){
resultArr[i] = "Never"
}
else if(newValArr[i]==0){
resultArr[i] = "Not my job";
}
if(i==26){
//alert('broken out of always loop');
}
}
for(p=0;p<14;p++){
if(resultArr[p]=="Agree"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Disagree"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Strongly Disagree"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Not my job"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(p==13){
//alert('broken out of summary table creation loop 1');
}
}
for(p=14;p<27;p++){
if(resultArr[p]=="Usually"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Occasionally"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Never"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Not my job"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(p==26){
//alert('broken out of summary table creation loop 2');
}
}
until this morning i had the entire page being outputted using the document.write function, but after reading a response to another post i made, i took all the print()'s away and split the js up into several functions. everything works fine on my page, apart from this section (which is used to print a list of answers a user gives to the questionnaire)
I have a main table and i want to basically get this function to write html to append specific table rows/cells without over writing the rest of the html.
Any help would be much appreciated!
Thanks,
Mike
here is the function i currently have to output the information:
function summary(){
var resultArr = new Array();
for(i=0;i<14;i++){
if(newValArr[i]==100){
resultArr[i] = "Strongly Agree";
}
if(newValArr[i]==75){
resultArr[i] = "Agree";
}
else if(newValArr[i]==50){
resultArr[i] = "Disagree"
}
else if(newValArr[i]==25){
resultArr[i] = "Strongly Disagree"
}
else if(newValArr[i]==0){
resultArr[i] = "Not my job";
}
if(i==13){
//alert('broken out of strongly agree loop');
}
}
for(i=14;i<27;i++){
if(newValArr[i]==100){
resultArr[i] = "Always";
}
if(newValArr[i]==75){
resultArr[i] = "Usually";
}
else if(newValArr[i]==50){
resultArr[i] = "Occasionally"
}
else if(newValArr[i]==25){
resultArr[i] = "Never"
}
else if(newValArr[i]==0){
resultArr[i] = "Not my job";
}
if(i==26){
//alert('broken out of always loop');
}
}
for(p=0;p<14;p++){
if(resultArr[p]=="Agree"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Disagree"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Strongly Disagree"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Not my job"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(p==13){
//alert('broken out of summary table creation loop 1');
}
}
for(p=14;p<27;p++){
if(resultArr[p]=="Usually"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Occasionally"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Never"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(resultArr[p]=="Not my job"){
document.write('<tr><td colspan="2">');
document.write('<p>'+(p+1)+'. You answered: '+resultArr[p]+'</p>');
document.write('</td></tr>');
}
if(p==26){
//alert('broken out of summary table creation loop 2');
}
}
until this morning i had the entire page being outputted using the document.write function, but after reading a response to another post i made, i took all the print()'s away and split the js up into several functions. everything works fine on my page, apart from this section (which is used to print a list of answers a user gives to the questionnaire)
I have a main table and i want to basically get this function to write html to append specific table rows/cells without over writing the rest of the html.
Any help would be much appreciated!
Thanks,
Mike
Could you please wrap your code with [code] tags the next time you post it?
Last edited by aniseed; Jan 26th, 2007 at 6:19 am.
![]() |
Similar Threads
- How can i add textboxes dynamically in an asp page (ASP)
- How to change the color of selected row of an HTML table without using CSS or Javascr (VB.NET)
- Navigation (Paging) in HTML table in VB.NET. (VB.NET)
- Call a external js function into another js function (JavaScript / DHTML / AJAX)
- Add textbox to editable div problem (JavaScript / DHTML / AJAX)
- Need help with HTMl Table echoing? (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: browser incompatibility? page wont finish loading
- Next Thread: Html Woes
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box bug calendar cart checkbox child class codes column cookies createrange() css cursor decimal design disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox focus form forms frameworks google gwt html htmlform ie8 iframe image() images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent php player post problem progressbar prototype redirect regex runtime scale scroll search select session shopping size sql text textarea toggle validation w3c web website window windowofwords windowsxp wysiwyg \n





