[COLOR=Indigo]hi .. i m using javascript with php and now i m in a severe problem. i m printing the questions through radio button in php and by validating them in javascript I want to delete the checked question. the questions are successfully deleted BUT .. the problem is this .. when the question remains only 1 then the delete function is failed to delete that question. i checked a lot but didnt find any other solution .. plz help me … code is given below[U][B]
PHP CODE
$i=1;
$query2=mysql_query(“select * from quiz where course_id=’$_SESSION[subject_value]'”);
while($rows=mysql_fetch_row($query2))
{
echo “<input type=’radio’ name=’question’ value=’$rows[0]’><font size=’3′>Question $i: $rows[2]</font><br><br>”;
echo “<font size=’3′><b>[Option 1]:</b> $rows[3] </font><br>”;
echo “<font size=’3′><b>[Option 2]:</b> $rows[4] </font><br>”;
echo “<font size=’3′><b>[Option 3]:</b> $rows[5] </font><br>”;
echo “<font size=’3′><b>[Option 4]: </b>$rows[6] </font><br><br>”;
echo “<font size=’3′><b>[Correct Answer]: </b>$rows[7] </font><br><br>”;
echo “</center>”;
$i++;
}
echo”
<table align=’center’>
<tr>
<td>
<input type=’button’ name=’update’ value=’ Update ‘ onClick=’validate(this.form,$i)’>
</td>
<td>
<input type=’button’ name=’del’ value=’ Delete ‘ onClick=’delque(this.form,$i)’ >
</td>
</form>
<form method=’GET’ action=’done_quest.php’>
<td>
<input type=’submit’ name=’con’ value=’ Done ‘ >
</td>
</form>
</tr>
</table></html>”;
[B][U]JAVASCRIPT CODE
function delque(form2,i)
{
var a;
var j;
var questionvalue;
var boolean=”false”;
for(j=0; j<i-1; j++)
{
if(form2.question[j].checked == true)
{
boolean=”true”;
break;
}
else
{
boolean=”false”;
}
}
if(boolean == “true”)
{
a=confirm(“Are You Sure?”);
if(a)
{
questionvalue=form2.question[j].value;
document.location=’delete_quest.php?questionvalue=’+questionvalue;
}
}
else if(boolean == “false”)
{
alert(“Please Select a Question”);
}
}