Hi,
This is what I want to know. I have a table which has the number of rows depended on what the number is in the spinner. This does work e.g If I enter 25 in spinner it comes up with 25 rows, if I enter 7 in spinner comes with 7 rows.
So my problem is this:
Lets say there are a number of rows in a table. What I have is a textarea where the user enters in their question and then submits the question, the question should be inserted and appear in the first row of the table under the “Question” column, the textarea goes blank and the user enters in his second question, if the user submits this then the question would appear in the second row, 3rd question into 3rd row, 4th question 4th into row etc.
Problem is that I do not know how to do this. I have attempted trying to do it but when I try and submit my first question the first row of the table under the “Question” column outputs “[object HTMLTableCellElement]”. Why does this happen and can somebody please be able to show me how to achieve what I want to achieve.
Thank You very much and any help will be greatly appreciated
Below is my javascript code:
<script type="text/javascript">
function insertQuestion() {
var questionDiv = document.getElementById("question");
var getQuestion = document.getElementById("questionTextarea");
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var questionCell = questionDiv.row.insertCell(getQuestion);
questionCell.innerHTML = getQuestion;
}
</script>
Below is html code:
//table where questions would be stored
<table id="qandatbl" align="center">
<thead>
<tr>
<th><span id="qidhead">Question No</span></th>
<th><span id="questionhead">Question</span></th>
</tr>
</thead>
<tbody>
<?php
$spinnerCount = $_POST['textQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) {?>
<tr>
<td id="qid"><?php echo $i; ?></td>
<td id="question"></td>
</tr>
</tbody>
<?php
}
}
?>
</table>
//table which consists of textarea and submit button
<form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table id='middleDetails' border='1'>
<tr>
<th class='tblheading' colspan='2'>SESSION DETAILS</th>
</tr>
<tr>
<td id="questionNum">Question No </td>
</tr>
<tr>
<td id="questionContent">Question:</td>
<td id="questionTextarea"><textarea rows="5" cols="40" id="questionTxt" name="questionText"></textarea></td>
</tr>
<tr>
<td id="addQuestionRow" colspan='2'><input id="addQuestion" type="button" value="Add Question" name="addQuestionBtn" onClick="insertQuestion()" /></td>
</tr>
</table>
</form>