这是我想要的response14.php?questionID=1&question=yes&approved=1
以下是我目前获得的response14.php?questionID=[object%20Object]&question=undefined&approved=1
这是js文件:
$(document).ready(function(){
$(".save_btn").on('click', function() {
var check = $("input[name=no]").is(":checked")?2:1;
var questionID = $("textarea[id=questionID]").val();
var question = $("textarea[value=question]").val();
location = "response14.php?questionID=" +questionID + "&question=" +question + "&approved=" +check;
以下是表格:
echo "<script src='viewsonly.js' type='text/javascript'> </script><br><center>";
include("db_conn.php");
$qry_strings4 = "SELECT * FROM `Y new questions`";
$preps4 = $pdo_conn->prepare($qry_strings4);
$preps4->execute();
// $row = $preps4->fetch(PDO::FETCH_ASSOC);
//echo "$count";
echo "<table style='border:0px; background-color:lightgrey; width:75%'><thead style='border:0px;'><tr style='border:0px solid white; background-color:#153E7E; text-align:left; color:white; padding: 5; margin: 5;'><th style='border:1px white; padding: 5; margin: 5;'>Question</th><th style='border:1px white; padding: 5; margin: 5;'>Response</th></tr></thead><tbody>";
while ($row = $preps4->fetch(PDO::FETCH_ASSOC)) {
echo "<tr style='border:1px white; background-color:lightgrey; color:black; padding: 5; margin: 5;'><td style='border:1px white; vertical-align:top; padding: 5; margin: 5;'>{$row['starName']}</td>
<td style='border:1px white; padding: 5; margin: 5;'><div id='wrap'>
<textarea cols='85' rows='2' id='{$row['questionID']}' class='response textbox'>{$row['question']}</textarea>
YES: <input type='checkbox' name='yes[]' value='yes'>
NO: <input type='checkbox' name='no[]' value='no'>";
}
echo "</tbody></table>";
echo "<button type='button' class='save_btn'>Save All</button><br>";
渲染html:
<td style='border:1px white; padding: 5; margin: 5;'><div id='wrap'>
<textarea cols='85' rows='2' id='3792' class='response textbox'>Hello C!!
Where can I send you fan mail? :)
I want your autograph and I'm from the Philippines :)
God bless Cooper!</textarea>
YES: <input type='checkbox' name='yes' value='yes'>
NO: <input type='checkbox' name='no' value='no'> </div></td></tr><tr style='border:1px white; background-color:lightgrey; color:black; padding: 5; margin: 5;'><td style='border:1px white; vertical-align:top; padding: 5; margin: 5;'>Gavin Casalegno</td>
<td style='border:1px white; padding: 5; margin: 5;'><div id='wrap'>
<textarea cols='85' rows='2' id='3793' class='response textbox'>What is your religion?
Do you believe in God?
How much you measure height?</textarea>
YES: <input type='checkbox' name='yes' value='yes'>
NO: <input type='checkbox' name='no' value='no'> </div></td></tr></tbody></table><button type='button' class='save_btn' style='align:right'>Save All</button><br>
关于如何解决这个问题的任何想法???
我刚刚按要求添加了渲染的html
答案 0 :(得分:2)
假设您有一个标识为questionID
的唯一元素,则在此分配中您应该在属性周围添加引号:
var questionID = $("textarea[id='questionID']").val();
即使你可能只是写
var questionID = $("#questionID").val();
您可以通过值属性
定位textareavar question = $("textarea[value=question]").val();
但textareas不提供值属性(有关详细信息,请参阅MDN)
最后,如果您要执行POST
请求,则需要使用ajax。 (因为您使用的是jQuery,请参阅$.post
方法的文档)
答案 1 :(得分:1)