Click to See Complete Forum and Search --> : Dynamically-built table problem
zchildress
12-11-2003, 11:54 PM
Can anyone offer some suggestions on how to correct this table alignment problem in the attached file? I've worked on it until I'm blue in the face and can't figure it out.
Any help would be greatly appreciated.
Gollum
12-12-2003, 02:20 AM
Your dummy example and the table generated by your code look quite different. For starters, your dummy has an outer table with one row with two cells (at 50% width each). Inside each cell is a table with rows for each question/answer to display.
Your dynamic table has one big table with one row per question and columns for choice, question number, question text and then (this is where it starts going wrong...) a series of answer columns, the first of which has a rowspan=num Questions.
You need to wrap your answers in their own table (so they align downwards, not acrosswards) - see following code...
answers_menu = "";
answers_text = "<td bgcolor=#eeeeee width=50% align=left valign=top cellpadding=3 rowspan="+questions.length+">";
answers_text += "<table>";
for(n=0;n<answers.length;n++) {
answers_text += "<tr>";
answers_menu += "<option>"+alpha.charAt(n);
answers_text += '<td><input type=checkbox disabled name="answer'+n+'"></td>'+'<td bgcolor=#eeeeee align=right valign=top><font size=2>'
+alpha.charAt(n)+"."+'</td><td bgcolor=#eeeeee align=left valign=top><font size=2>'+answers[alpha.charAt(n)]+'</td>';
answers_text += "</tr>"
}
answers_text += "</table></td>";
zchildress
12-12-2003, 02:46 AM
That definitely did the trick, Gollum!
I see where you added
answers_text += "<table>";
to establish the table and then ending it at
answers_text += "</table></td>";
You're right...that was my downfall. I was trying to continue the pattern and lay it out as a six column table.
Many, many thanks for setting me straight!
zchildress
12-12-2003, 04:01 AM
Mind if I ask two followup questions?
FIRST QUESTION STUFF:
--------------------------
I was wanting to put two of these scripts on one page (Part 1 and Part 2). I tried adding a "1" to all pertinent parts of one of the scripts...for instance:
form name="matching" now equals form name="matching1"
document.matching.answer now equals document.matching1.answer
document.matching.choice now equals document.matching1.choice
textarea name="evaluation" now equals textarea name="evaluation1"
etc.
But then the one I've changed doesn't work properly. It still loads the answers into the second script textarea. Does that have to do with "selectedIndex"? Am I on the right track at least?
SECOND QUESTION STUFF:
--------------------------
Also, the way the script was originally written, when you first load it, every drop down selector shows the first answer, "a". That's because this code is included
answers = new Object();
answers["a"] = "answer";
answers["b"] = "answer";
answers["c"] = "answer";
answers["d"] = "answer";
answers.length = 4;
I tried simply adding this line:
answers[''] = null;
so that the complete group is now
answers = new Object();
answers[""] = null;
answers["a"] = "answer";
answers["b"] = "answer";
answers["c"] = "answer";
answers["d"] = "answer";
answers.length = 5;
in order to make the drop down selectors show a blank selection when first loaded...but that isn't working. Any advice?
Whew...can you tell that I'm a newbie at javascripting? ;)