doutangdan3588 2013-09-19 09:50
浏览 39
已采纳

object对象和未定义的GET变量

Here's what I'm trying to get response14.php?questionID=1&question=yes&approved=1

Here's what I'm currently getting response14.php?questionID=[object%20Object]&question=undefined&approved=1

Here's the js file:

$(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;

And here's the form:

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>";

rendered 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'> &nbsp;&nbsp;&nbsp;
    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'> &nbsp;&nbsp;&nbsp;
    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>

Any ideas on how to fix this???

I have just added the rendered html as requested

  • 写回答

2条回答 默认 最新

  • dovs36921 2013-09-19 09:59
    关注

    Assuming you have a unique element with id questionID, in this assignment you should add quotes around the attribute:

    var questionID = $("textarea[id='questionID']").val();
    

    even you may simply write

    var questionID = $("#questionID").val();
    

    Here you're targeting a textarea by a value attribute,

    var question = $("textarea[value=question]").val();
    

    but textareas don't provide a value attribute (see MDN for further information)


    Finally, if you want to perform a POST request you need to use ajax. (since you're using jQuery see the documentation of $.post method)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)