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

Recommended Answers

All 2 Replies

Could you please wrap your code with [[/u]code[u]] tags the next time you post it?

ok i will do. im still stuck though!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.