0

Not sure if i should be using php or JavaScript however i have a form that uses the following checkboxes

td>How do you get to work?</td>
                    <td><input type="checkbox" name="vehicle" value="Train" />Train
                    <input type="checkbox" name="transport[]" value="Bus" />Bus
                    <input type="checkbox" name="transport[]" value="Car" />Car
                    <input type="checkbox" name="transport[]" value="Bicycle" />Bicycle
                    <input type="checkbox" name="transport[]" value="Walk" />Walk</td>
                    </tr>

In my php file i have to print to the screen the transport options which have been selected however before i do this i have to use a for loop to iterate over the elements in the array and have to use the function count to determine how many elements are in the array. I have no idea what why this should be written and also if the checkboxes names transport [] should include numbers for their position in the array like transport [0] etc. Any help would be great.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by vibhaJ
0
<?
    if(form is submitted)
    {
        $transportAll = $_POST['transport'];
        foreach($transportAll as $transport)
        {
            echo '<br />You have selected:'.$transport;
        }
        echo '<br />Total:'.count($transportAll);
    }
?>
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.