javascript - Returning Error If Radio Button NOT selected - PHP -


I have searched long ago through questions about PHP and radio buttons, but I still have some Help is not found in my situation I am creating a quiz for a server side scripting class. I'm stuck on the actual quiz part I need an error message which resonates if the user does not choose to answer any questions. Instead, when I press the Submit button without choosing any option, I'm automatically redirected to the results page. How can I correct my code so that the user gets an error message when submitting without answering all the questions? In the attempt to check the radio button below and the next step, I have written the current code.

   & Lt; Input type = "radio" name = "creature" value = "cornish pixels" & lt ;? Php if (isset ($ _ session ["animal"]) & amp; $ _SESSION ["animal"] = "cornice pics") {resonant "check";}? & Gt; & Gt; Cornish Pixies & lt; Br> & Lt ;! - php code check to see that the radio button has been selected - & gt; & Lt; Input type = "radio" name = "creature" value = "clydesdales" & lt ;? Php if (isset ($ _ session ["animal"]) & amp; $ _SESSION ["animal"] = "clideless") {resonant "check";}? & Gt; & Gt; Clydesdales & lt; Br> & Lt; Input type = "radio" name = "creature" value = "hippogriffs" & lt ;? Php if (isset ($ _se [["creature"]) & amp; $ _SESSION ["animal"] = "hippogriff") {resonant "check";}? & Gt; & Gt; Hippogriffs & lt; Br> & Lt; Input type = "radio" name = "creature" value = "thestrals" & lt ;? Php if (isset ($ _ session ["animal"]) & amp; $ _SESSION ["animal"] = "theory") {resonant "check";}? & Gt; & Gt; Thestrals & lt; Br> & Lt; Input type = "hidden" name = "sent" value = "sent" onclick = "Project1_Page2.php" & gt; & Lt; Input type = "submit" name = "gaurets" value = "get results?" & Gt; | & Lt; Input type = "reset" name = "resetquoues" value = "reset quiz" & gt; & Lt; / Form & gt; & Lt; / Article & gt; & Lt ;? Php if (isset ($ _GET ["sent"])) {resonant "script = type = 'javascript'>;); If (! Isset ($ _GET ["question1"])) {// Quiz Question 1 Check $ _SESSION ["Author"] = $ _ Received ["Author"]; } Else {echo "document.getElementById ('Q1'). Style.backgroundColor = '#ffcccc'; document.getElementById ('question1_error'). Style.display = 'block';"; } If (! Isset ($ _GET ["question2"])) {// Quiz Question 2 Check $ _SESSION ["Godfather"] = $ _ GET ["Godfather"]; } Else {echo "document.getElementById ('Q2'). Style.backgroundColor = '#ffcccc'; document.getElementById ('question2_error'). Style.display = 'block';"; } If (! Isset ($ _GET ["question3"])) {// Quiz Question 3 $ _SESSION ["prison"] = $ _ [["prison"]; } Else {echo "document.getElementById ('Question 3'). Style.backgroundColor = '#ffcccc'; document.getElementById ('question3_error'). Style.display = 'block';"; } If (! Isset ($ _GET ["question4"])) {// quiz question 4 check $ _SESSION ["badguy"] = $ _GET ["badguy"]; } Else {echo "document.getElementById ('Q4'). Style.backgroundColor = '#ffcccc'; document.getElementById ('question4_error'). Style.display = 'block';"; } If (! Isset ($ _GET ["question5"])) {// quiz question 5 check $ _SESSION ["animal"] = $ _ receive ["creature"]; } Else {echo "document.getElementById ('Question 5'). Style.backgroundColor = '#ffcccc'; document.getElementById ('question5_error'). Style.display = 'block';"; Echo "& lt; / script & gt;"; }? & Gt;  

Without seeing your HTML, it is hard to say but here are some suggestions < / P>

In your form tag, delete the "Action" attribute

  & lt; Form method = "post / get" & gt;  

then create a variable

  $ haserror = false;  

And I'm not sure what you are trying to achieve here, but change the code like this

  if (! Isset ( $ _ GET [Question 1 "])) {// Quiz Question 1 Check $ _SESSION [" Author "] = $ _ Received [" Author "]; Echo" document.getElementById ('Question 1'). Style.backgroundColor = '#ffcccc'; Document.getElementById ('question1_error'). Style.display = 'block'; ";  

$ Haider = true;}

Do this for all checkboxes

< P> Then show your page in the result

  if echo ($$$$$); 'lt; META http-equiv = "refresh" content = "0; URL = newpage.php "& gt; ';}  

However I suggest writing the whole thing again, because you are coming to it incorrectly


Comments