У меня небольшая проблема:
У меня есть функция, в которой он будет добавлять строки после того, как пользователь ввел вопрос в текстовой области, а затем отправит вопрос, если вопрос правильный, он добавитстрока в таблице с вопросом внутри строки.
Это работает во всех основных браузерах, кроме одного (удивительно, удивительно, что это Internet Explorer).В Internet Explorer он не добавляет строку при отправке вопроса, после нажатия кнопки «Отправить» он не добавляет строку.Моя проверка вопроса работает, но не добавляет строку, когда вопрос действителен.
Почему моя функция не работает в Internet Explorer?
Ниже приведен мой код:
Javascript:
function insertQuestion(form) {
var row = document.createElement("tr");
var cell,
input,
alertErrors = "",
// Note, this is just so it's declared...
qnum = 1;
// Note, I'm using the .value instead of copying it
// Also note the .length on the second check
if (form.questionText.value == ""){
alertErrors += "\nYou have not entered a valid Question";
} else if (form.questionText.value.length < 5){
alertErrors += "\nYou have not entered a valid Question";
}
// Stop execution with a return
if (alertErrors != "") {
alert(alertErrors);
return;
}
cell = document.createElement("td"),
input = document.createElement("textarea");
cell.className = "question";
input.name = "question_" + qnum;
input.value = form.questionText.value;
cell.appendChild(input);
row.appendChild(cell);
document.getElementById("qandatbl").appendChild(row);
form.numberOfQuestions.value = qnum;
++qnum;
document.getElementById("questionNum").innerHTML = qnum;
form.questionText.value = "";
}
HTML-таблица и текстовое поле и кнопка отправки вопроса:
<form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validateForm(this);" >
//below is question textarea and submit button
<table id="middleDetails" border="1">
<tr>
<th colspan="2">
Question Number <span id="questionNum">1</span>
</th>
</tr>
<tr>
<td>Question:</td>
<td>
<textarea rows="5" cols="40" name="questionText"></textarea>
</td>
<tr>
<th colspan="2">
<input name="addQuestion" type="button" value="Add Question" onClick="insertQuestion(this.form)" />
</th>
</tr>
</table>
<hr/>
//below is where the rows get added after question is submitted and valid
<table id="qandatbl" border="1">
<tr>
<th class="qid">Question No</th>
<th class="question">Question</th>
</tr>
</table>
<input type="submit" value="Submit questions to database" />
<input type="hidden" name="numberOfQuestions" value="0" />
</form>