Я хочу, чтобы пользователь мог добавить вопрос из строки таблицы в текстовое поле. Текстовая область, на которую встает вопрос, зависит от кнопки «.plus», которую пользователь выбрал для выбора своего вопроса.Функция ниже ничего не добавляет в textarea
E.g. Если пользователь нажал кнопку «плюс» в верхней части страницы, тогда вопрос, когда пользователь нажимает кнопку «Добавить», попадает в текстовое поле вверху страницы.
Другое, например. Если пользователь нажал кнопку «плюс» в пятой строке таблицы, вопрос, когда пользователь нажимает кнопку «Добавить», попадает в текстовую область внутри этой строки (5-я строка).
Проблема, с которой я сталкиваюсь, заключается в том, что когда пользователь нажимает кнопку «Добавить», ничего не происходит. Предполагается закрыть модальное окно и вставить вопрос в правильное текстовое поле, но ничего не происходит. Он не закрывает модальное окно и не вставляет вопрос в текстовое поле.
Что я делаю неправильно?
Ниже приведен код для приложения:
<head>
<script type="text/javascript">
function insertQuestion(form) {
var $tbody = $('#qandatbl > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
var $plusrow = $("<td class='plusrow'></td>");
var $question = $("<td class='question'></td>");
$('.questionTextArea').each(function() {
var $this = $(this);
var $questionText = $("<textarea class='textAreaQuestion'></textarea>").attr('name', $this.attr('name') + "[]").attr('value', $this.val());
$question.append($questionText);
});
$('.plusimage').each(function() {
var $this = $(this);
var $plusimagerow = $("<a onclick='return plusbutton();'><img src='Images/plussign.jpg' width='30' height='30' alt='Look Up Previous Question' class='imageplus'/></a>").attr('name', $this.attr('name') + "[]").attr('value', $this.val());
$plusrow.append($plusimagerow);
});
$tr.append($plusrow);
$tr.append($question);
$tbody.append($tr);
form.questionText.value = "";
$('.questionTextArea').val('');
}
function plusbutton() {
// Display an external page using an iframe
var src = "previousquestions.php";
$.modal('<iframe src="' + src + '" style="border:0;width:100%;height:100%;">');
return false;
}
function closewindow() {
$.modal.close();
return false;
}
$(document).on('click', '.add', function() {
console.log("clicked");
//lets get our Question Text...
var theQuestion = $("td:first-child", $(this).parent()).text();
//the row is present, let's then make sure that the proper cell gets oru data.
if ($('.activePlusRow').length > 0) {
$('.activePlusRow').next('.textAreaQuestion').val(theQuestion);
$('.activePlusRow').removeClass('activePlusRow');
}
$.modal.close();
return true;
});
$(document).on('click', '.plusrow', function() {
//adding a unique class for the purpose of the click.
$(this).addClass('activePlusRow');
});
</script>
</head>
<body>
<form id="QandA" action="<?php echo htmlentities($action); ?>" method="post">
<div id="detailsBlock">
<table id="question">
<tr>
<td rowspan="3">Question:</td>
<td rowspan="3">
<textarea class="questionTextArea" rows="5" cols="40" name="questionText"></textarea>
</td>
</tr>
</table>
<table id="plus" align="center">
<tr>
<th>
<a onclick="return plusbutton();">
<img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" name="plusbuttonrow"/>
</a>
<span id="plussignmsg">(Click Plus Sign to look
<br/>up Previous Questions)</span>
</th>
</tr>
</table>
<table id="questionBtn" align="center">
<tr>
<th>
<input id="addQuestionBtn" name="addQuestion" type="button" value="Add Question"
onClick="insertQuestion(this.form)" />
</th>
</tr>
</table>
</div>
<hr/>
<div id="details">
<table id="qandatbl" align="center">
<thead>
<tr>
<th class="plusrow"></th>
<th class="question">Question</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</form>
</body>
Детали, хранящаяся в модальном окне происходит от отдельного сценария, известного как «previousquestions.php», Ниже приведен код, где он показывает результат из поле «QuestionContent» отображается только, и это кнопка «Добавить» после того, как пользователь составил поиска:
<?php
$output = "";
$output .= "
<table border='1' id='resulttbl'>
<tr>
<th id='questionth'>Question</th>
</tr>
";
while ($questionrow = mysql_fetch_assoc($questionresult)) {
$output .= "
<tr>
<td id='questiontd'>{$questionrow['QuestionContent']}</td>
<td id='addtd'><button type='button' class='add'>Add</button></td>
</tr>";
}
$output .= " </table>";
echo $output;
}
}
?>
Спасибо вам
Что мне установить .val() на? – user1394925