Help with Uni assignment


can you tell me how to be able to prevent the form from submitting without having a box ticked. Ive tried some code but having trouble getting it to work…


Aviation and Aerospace
Oil and Gas


Hi. I moved your topic to Javascript forum, because… you can do this with javascript like this:


Thanks for the reply, I have managed to get that working although I am still having some trouble.

I need the error box to come up when none of them have been selected. And this works!

Although when I tick a box that is not the first one “Markets” then it still comes up with the alert. I know if I could change the ID’s on the other checkboxes but what would I need to change in the code instead of just having “Markets” in the check.

You can add id to each checkbox, say Markets1, Markets2,… And then add condition for each of checkboxes:

if(document.getElementById('Markets1').checked==false && document.getElementById('Markets2').checked==false && document.getElementById('Markets3').checked==false ){

Thanks so much that has helped greatly. I have now came to another hurdle.

I need to create a new final page. this is basically a confirmation page of whatever the user has inputed into the form.

I need to carry through whatever boxes are checked on a check box and have them presented on a confirmation page and also how much the total will cost will need to be carried through.

Here is the code I have, hopefully you can make some sense of it. it does work for everything I need it to do.


Stock Market
<FORM NAME="priceForm" method="post" action="goodbye.php" onSubmit="return CheckForm()">
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets1" VALUE="Aviation and Aerospace"
  	      onClick="showPrices(1)" ></INPUT></TD>
      <TD>Aviation and Aerospace</TD>
  	<TD><INPUT TYPE="text" NAME="AviationField" SIZE="5" VALUE="" ></INPUT></TD>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets2" VALUE="Banks"
  	<TD><INPUT TYPE="text" NAME="BanksField" SIZE="5" VALUE=""></INPUT></TD>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets3" VALUE="Construction"
  	<TD><INPUT TYPE="text" NAME="ConstructionField" SIZE="5" VALUE=""></INPUT></TD>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets4" VALUE="Electronics"
  	<TD><INPUT TYPE="text" NAME="ElectronicsField" SIZE="5" VALUE=""></INPUT></TD>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets5" VALUE="Oil and Gas"
      <TD>Oil and Gas</TD>
  	<TD><INPUT TYPE="text" NAME="OilandGasField" SIZE="5" VALUE=""></INPUT></TD>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets6" VALUE="Pharmaceuticals"
  	<TD><INPUT TYPE="text" NAME="PharmaceuticalsField" SIZE="5" VALUE=""></INPUT></TD>


  Sorry, no scripting support

I have used a


and got some of the information through but its in a weird way…

Array ( [Markets] => Array (=> Aviation and Aerospace [1] => Banks [2] => Construction ) [AviationField] => 50 [BanksField] => 25 [ConstructionField] => 30 [ElectronicsField] => [OilandGasField] => [PharmaceuticalsField] => [TotalField] => 105 [CodeField] => Stephen [submit] => Subscribe )

How do I maniputlate that so I can just use the variables that have been checked and also use the total?

You need to change name of all checkboxes to array: NAME=“Markets[]”, here is an example:

This array will contain all the values what you checked: $_POST[‘Markets’]
[php]if(is_array($_POST[‘Markets’]) foreach($_POST[‘Markets’] as $value){
echo $value;

Sponsor our Newsletter | Privacy Policy | Terms of Service