簡體   English   中英

使用php通過javascript傳遞參數

[英]Passing Parameter through javascript with php

我必須使用javascript函數顯示重定向頁面的增量為1。 但是當我嘗試這個時,我得到了NaN錯誤。 任何人都可以幫我解決問題。我已經附上了我的來源。 像這樣的quiz.php?qusId = NaN。

    <script type="text/javascript">
        function handler(var1,quizId) {
            alert(var1);
            var id = parseInt(quizId);
            window.location = "quiz.php?qusId="+parseInt(quid(id));
        }
        function quid(quzId){
            if(quzId == 1){
                return 1;
            }else{
                return quzId++;
            }
        }
    </script>
</head>
<body>
    <?php 
        $qusId=$_GET['qusId'];
        ?>
        <form action="test.php" method="POST">
            <?php
                $result = select("SELECT * FROM questions WHERE question_id='$qusId'");
                //$row = mysql_fetch_array($result);
                $i=$_GET['qusId'];
                while($row = mysql_fetch_array($result))
                {
                    ?>
                        <table width="581" height="299" border="1">
                            <tr>
                                <td>Union Assurance Questionnaire</td>
                            </tr>
                            <tr>
                                <td>
                                    <?php 
                                        echo $i.'.' .$row['questions']; 
                                        $i++;
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <?php 
                                        $qId=$row['question_id'];
                                        $result1=select("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()");
                                        while($row1=mysql_fetch_array($result1)){
                                            ?>
                                                <input type="radio" name="answers" value="<?php echo $row1['answers'];?>"  onclick="handler('<?php echo $row1["feedback"]; ?>,<?php echo $qusId;?>')" /><?php echo $row1['answers']; ?><br/>
                                            <?php 
                                        } 
                                    ?>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table>
                    <?php
                }
            ?>
        </form>

在您的點擊處理程序中,您已經擁有了

handler('<?php echo $row1["feedback"]; ?>,<?php echo $qusId;?>')

您已將單引號放在錯誤的位置 - 它將作為單個參數傳遞到您的“處理程序”函數中。 嘗試改為:

handler('<?php echo $row1["feedback"]; ?>',<?php echo $qusId;?>)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM