/    Sign up×
Community /Pin to ProfileBookmark

Can Anyone Solve my PLOBLEM :confused:

[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[/COLOR][U][B]
PHP CODE[/B]
[/U]

$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[/U][/B]

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”);
}
}

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@slyfoxSep 20.2005 — your "for statement" is incorrect..

for(j=0; j<i-1; j++) should be for(j=0; j<i; j++)

it won't run if 0 is already -1
Copy linkTweet thisAlerts:
@HunnyauthorSep 21.2005 — i also done this before .. but it is not solved.. the browser is giving error which is " 'question[...].checked' is null or not an object " ... wht shuld i do now ? ?
Copy linkTweet thisAlerts:
@felgallSep 21.2005 — Radio buttons don't have a "checked" state they have a "selected" state. Check boxes have a "checked" state.
Copy linkTweet thisAlerts:
@HunnyauthorSep 23.2005 — again problem is not solved by the selected state . Browser shows the error question[...].selected is null or not an object ?
×

Success!

Help @Hunny spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...