I have an application which you can test in my jsfiddle to see how it works, jsfiddle. Now what this app does is allow users to select options and answers for each question, (the app on jsfiddle does not show the question as it is not needed for this question).
Now what happens is the user selects an option, types in the number of answers he/she wants and then selects the answers from the buttons below. The user will add a question and then a new row will appear in the table showing the answers selected.
Example on how to use the app so you can try it yourself in jsfiddle:
-
open the grid (open grid link) and select option “4”.
-
Type in number 2 in the “Number of Answers” Textbox (#numberAnswerTxt)
-
Select Buttons “A” and “C”.
-
Click on “Add Question” button.
Now as you can see a new table row appears but nothing is under the “Answer2 column except an empty textbox. (Don’t need textbox).
What I want is the exact copy of the Answers buttons (if you follow example in fiddle then its Buttons “A” to “D” with “A” and “C” selected) to be displayed in the “Answer” column when an answer is submitted in a new table row. I want to show it as the buttons as they are but I have absolutly no idea how to do this.
Does anyone know how to do it?
The code which controls the new table row for the “Answer” column is below:
cell = document.createElement("td");
cell.className = "answer";
input = document.createElement("input");
input.name = "answer_" + qnum;
cell.appendChild(input);
row.appendChild(cell);
This can be found in the function insertQuestion(form) which is near the end of the Jsfiddle Javascript section.
I’m not sure if this is what you have in mind, but the following modified function will copy the selected buttons (without the on/off class and events) to the new row. Adjust as necessary by adding additional classes to get the styling exactly the way you want. Note I recommend not setting the style property directly on the element as you are doing. It should be enough to use CSS to do this, perhaps using a rule with
:nth-childto get the wrapping you need. See an updated fiddle at http://jsfiddle.net/YTh5Y/.