Reputation: 611
I have to show redirect the page with increment by one using javascript function. But When I try this I got NaN Error . Can anyone please help me to fix the Problem.I Have attached My Source Below. like this 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
}
?>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<?php
}
?>
</form>
Upvotes: 0
Views: 207
Reputation: 1014
In your click handler, you've got
handler('<?php echo $row1["feedback"]; ?>,<?php echo $qusId;?>')
You've put the single quotes in the wrong place - it's being passed into your 'handler' function as a single parameter. Try instead:
handler('<?php echo $row1["feedback"]; ?>',<?php echo $qusId;?>)
Upvotes: 2