I have a simple example of my form:

<html>
<head><title></title></head>
<body>
<table>
    <form method="POST" action="checkboxes.php">
    <tr>
        <td>
Choose Event
</td>
    </tr>
    <tr>
<td>
Soccer Game
</td>
<td>
    <input name="Choice[]" type="checkbox" value="1">
</td>
<td>
    <input name="Date[]" type="textbox" value="01/01/2007">
</td>
</tr>
<tr>
<td>
Baseball Game
</td>
<td>
    <input name="Choice[]" type="checkbox" value="2">
</td>
<td>
    <input name="Date[]" type="textbox" value="01/01/2007">
</td>
</tr>
<tr>
<td>
Basketball Game
</td>
<td>
    <input name="Choice[]" type="checkbox" value="3">
</td>
<td>
    <input name="Date[]" type="textbox" value="01/01/2007">
</td>
</tr>
<tr>
<td>
    <input type="submit" value="submit">
</td>
</tr>
</form>
</table>
</body>
</html>

 

Since the date fields are filled in, they are being sent in the _POST array, irrespective of when the 'Choice' checkbox has been selected. If I choose two of the three checkboxes, the resultant arrays are:

Array ( [0] => 1 [1] => 2 )
Array ( [0] => 01/01/2007 [1] => 01/01/2007 [2] => 01/01/2007 )
 

How do I just get the dates that correspond to the checkboxes that were selected??

    <?php
    if (!isset($_POST['submit']))
    {
    	$games = array(
    	'Soccer' => '01/01/2007',
    	'Baseball' => '01/01/2007',
    	'Basketball' => '01/01/2007'	
    	);
    
    echo '<form action="" method="POST">';
    
    foreach ($games as $key => $value)
    {
    	echo $key . ': <input type="checkbox" name="data[' . $key . '][check]" value="Y"><br>
    	date: <input type="textbox" name="data[' . $key . '][date]" value="' . $value . '">
    	<br><br>
    	';
    }
    
    echo '
    <input type="submit" name="submit" value="submit">
    </form>
    ';
    }
    else
    {
    	$i = 0;
    	foreach ($_POST['data'] as $key => $value)
    	{
    		if (isset($value['check']))
    		{
    			echo $key . ' = ' . $value['date'] . '<br>';
    			$i++;
    		}
    	}	
    	if (!$i) {echo 'you did not check anything';}
    }
    ?>
    

      Sounds like a job for Javascript. Try adapting these functions. 1st, give your checkboxes the name "checkboxes". 2nd, give them each a unique id. 3rd, create a hidden text input field named "idstring" and put it inside a form. It will hold the string returned.

      Hope this helps.

      function collectCheckedItems()
      {
      var checkboxes = document.getElementsByName("checkboxes")

      var idstring = ""

      for( i=0 ; i < checkboxes.length ; ++i )
      {
      if( checkboxes[ i ].checked )
      idstring = idstring + checkboxes[ i ].id + ","
      }

      if( idstring.length > 0 )
      idstring = idstring.slice( 0 , idstring.length - 1 )

      return idstring
      }

      function SubmitForDeletion()
      {
      var idstringfield = document.getElementById("idstring")
      idstringfield.value = collectCheckedItems()

      if( idstringfield.value.length == 0 )
      {
      alert( "No records checked for deletion." )
      return false
      }
      }

      j_70 wrote:

      I have a simple example of my form:

      <html>
      <head><title></title></head>
      <body>
      <table>
          <form method="POST" action="checkboxes.php">
          <tr>
              <td>
      Choose Event
      </td>
          </tr>
          <tr>
      <td>
      Soccer Game
      </td>
      <td>
          <input name="Choice[]" type="checkbox" value="1">
      </td>
      <td>
          <input name="Date[]" type="textbox" value="01/01/2007">
      </td>
      </tr>
      <tr>
      <td>
      Baseball Game
      </td>
      <td>
          <input name="Choice[]" type="checkbox" value="2">
      </td>
      <td>
          <input name="Date[]" type="textbox" value="01/01/2007">
      </td>
      </tr>
      <tr>
      <td>
      Basketball Game
      </td>
      <td>
          <input name="Choice[]" type="checkbox" value="3">
      </td>
      <td>
          <input name="Date[]" type="textbox" value="01/01/2007">
      </td>
      </tr>
      <tr>
      <td>
          <input type="submit" value="submit">
      </td>
      </tr>
      </form>
      </table>
      </body>
      </html>
      
       

      Since the date fields are filled in, they are being sent in the _POST array, irrespective of when the 'Choice' checkbox has been selected. If I choose two of the three checkboxes, the resultant arrays are:

      Array ( [0] => 1 [1] => 2 )
      Array ( [0] => 01/01/2007 [1] => 01/01/2007 [2] => 01/01/2007 )
       

      How do I just get the dates that correspond to the checkboxes that were selected??

        Javascript can be turned off. For this, PHP would be the best solution.

          "Javascript can be turned off. For this, PHP would be the best solution."

          I would tend to agree. Could you put some code around your response.

            j_70 wrote:

            Could you put some code around your response.

            Isn't that what devinemke did?

              OK, now one more element of complexity. I may have been guilty of trying to make the example too simple. There are two dates associated with each event. How do I pass a start date and end date associated with each event?

                Write a Reply...