Help with Uni assignment

Hello

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…

[php]

Price(£)
Aviation and Aerospace
Banks
Construction
Electronics
Oil and Gas
Pharmaceuticals
Total:

[/php]

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

[/php]

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.

[php]

Stock Market
<FORM NAME="priceForm" method="post" action="goodbye.php" onSubmit="return CheckForm()">
  <P/>
  <TABLE>
  <TR>
      <TD></TD>
  	<TD></TD>
      <TD>Price(£)</TD>
  </TR>
  <TR>
      <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>
  </TR>
  <TR>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets2" VALUE="Banks"
  	      onClick="showPrices(2)"></INPUT></TD>
      <TD>Banks</TD>
  	<TD><INPUT TYPE="text" NAME="BanksField" SIZE="5" VALUE=""></INPUT></TD>
  </TR>
   <TR>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets3" VALUE="Construction"
  	      onClick="showPrices(3)"></INPUT></TD>
      <TD>Construction</TD>
  	<TD><INPUT TYPE="text" NAME="ConstructionField" SIZE="5" VALUE=""></INPUT></TD>
  </TR>
  <TR>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets4" VALUE="Electronics"
  	      onClick="showPrices(4)"></INPUT></TD>
      <TD>Electronics</TD>
  	<TD><INPUT TYPE="text" NAME="ElectronicsField" SIZE="5" VALUE=""></INPUT></TD>
  </TR>
  <TR>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets5" VALUE="Oil and Gas"
  	      onClick="showPrices(5)"></INPUT></TD>
      <TD>Oil and Gas</TD>
  	<TD><INPUT TYPE="text" NAME="OilandGasField" SIZE="5" VALUE=""></INPUT></TD>
  </TR>
  <TR>
      <TD><INPUT TYPE="checkbox" NAME="Markets" ID="Markets6" VALUE="Pharmaceuticals"
  	      onClick="showPrices(6)"></INPUT></TD>
      <TD>Pharmaceuticals</TD>
  	<TD><INPUT TYPE="text" NAME="PharmaceuticalsField" SIZE="5" VALUE=""></INPUT></TD>
  </TR>
Total:

</FORM>

<HR>
<NOSCRIPT>
  Sorry, no scripting support
</NOSCRIPT>
[/php]

I have used a

print_r($_POST);

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:
[php][/php]

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;
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service