2

I have multiple radio buttons that are linked together. I want to set the value of each radio button based on whether it is clicked/set or not

Edit I have included the full code for one set of radio buttons. A set since they are all called the same name.
>

<td><br><input type="radio" name="meal1" <?php if (isset($meal2)){
    echo "checked", "value = '1'";
 } else {
    echo "value = '0'";
 }
 ?>>
</td>

<td><br><input type="radio" name="meal1" <?php if (isset($meal3)){
    echo "checked", "value = '1'";
} else {
    echo "value = '0'";
}
;?>>
</td>

<td><br><input type="radio" name="meal1" <?php if (isset($meal4)){
    echo "checked", "value = '1'";
} else {
    echo "value = '0'";
}
;?>>
</td>

Edit This code is now changed from previous one just to echo the output of each

if(isset($_POST['order'])){
if(!isset($_POST['meal1'])){
    echo "Radio buttons not set.";
} else {
$meal1 = $_POST['meal1'];
$meal2 = $_POST['meal1'];
$meal3 = $_POST['meal1'];
$meal4 = $_POST['meal1'];

print_r($meal1);
print_r($meal2);
print_r($meal3);
print_r($meal4);
}

When I execute the code below, after clicking on of the radio buttons. The output is 0,0,0,0. I would like the output to 1,0,0,0 Since I have clicked the first radio button.

1
  • Well I don't see in the code you posted where you're setting the value of $_POST['meal1']. Commented Dec 18, 2014 at 10:49

1 Answer 1

1

Your code

 echo "checked"; "value = '1'";

Does nothing. You stop the echo command half way through.

echo "checked value='1'";

should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.