0

ok so far from working wit php I come to realize that its bascially html and javascript coding together, i was never taught any of this so basically just been trying to teach myself

my question is this, I have uploaded a screenshot of something I am working on
theres option 1, 2 and 3 and then a bonus option if all three are selected

say for just theory option 1 if checked is worth 25 points
option 2 if checked is 30 points
option 3 if checked is 40 points
if all three are checked then bonus adds 75 tp op1+op2+op3

i know this is roughly just all if/else commands but not to familiar with the coding to possibly choose if two out of the three were selected to add those, if none are selected return an error, and if the bonus is selected without clicking all three return an error

any help would be much appreciated, I know this is a very basic tasks especially someone with experience in this area

Attachments grip.jpg 418.72 KB
3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
0

Try:

<?php
if( isset($_POST['selectedBox']) && !empty($_POST['selectedBox']) )
{
  $total=0;
  foreach($_POST['selectedBox'] as $index=>$value)
  {
    echo 'Checked Item '. $index;
    $total += $value;
  }

  if( 3==count($_POST['selectedBox']) )
  {
    echo 'you get 75 bonus points for selecting all';
    $total +=75;
  }

  echo 'Your total is' . $total;
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type='checkbox' name='selectedBox[1]' value='25'/>
<input type='checkbox' name='selectedBox[2]' value='30'/>
<input type='checkbox' name='selectedBox[3]' value='40'/>
<input type='submit' name='Submit' value='Submit' />
</form>
0

o

k so far from working wit php I come to realize that its bascially html and javascript coding together, i was never taught any of this so basically just been trying to teach myself

I think you've been misinformed. php and JS, while sharing similar commands, like many languages, are quite different. In addition, although you can output html with php, you can output anything with it - js/json, css, xml, html, etc etc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.