Jump to content

selecting checked checkbox


dvayne

Recommended Posts

<?

$check=$_POST["check"];

$chk=implode(",",$check);
echo $chk;
?>
<form action="" method="post">
<input type="checkbox" name="check[]" id="check" value="hai" >hai
<input type="checkbox" name="check[]" id="check" value="how">how
<input type="checkbox" name="check[]" id="check" value="are">are
<input type="checkbox" name="check[]" id="check" value="you">you
<input type="submit" name="submit" value="submit">
</form>

On the HTML form, name use this instead of a normal input:

<input type="checkbox" name="interests[]" value="Music" /> Music

Just an example.  Notice the name, with the [] on the end.

To use that in PHP, do this:

<?php
foreach ($_POST['interests'] as $key=>$value) {
   //do something with $value
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.