Jump to content

[SOLVED] Detecting Checkboxes and Option Lists


jayjay76

Recommended Posts

I am trying to figure out how to detect a <Form> check box being checked in a PHP script.  Likewise, I am trying to figure out how to detect which option was chosen in a <option> list of drop-down items in a form.

 

For example, a simplistic form would be something like:

 

 

<Form Method="Post" Action="./php/test.php">

<Center>

  <Table Width='333' border='0' CellPadding='0' CellSpacing='0' bgcolor='#53B5FD'>

        <TR>

            <TD><B>Order Type: </td>

            <TD><div align='right'>

                    <select name='type'>

                    <option value='test1' selected>Test 1</option>

                    <option value='test2'>Test 2</option>

                    <option value='test3'>Test 3</option>

                    </select></div></td>

      </tr>

      <TR>

            <TD><input type='checkbox' name='checktest1' value='On'>Check Me 1</td>

            <TD><input type='checkbox' name='checktest2' value='On'>Check Me 2</td>

            <TD><input type='checkbox' name='checktest3' value='On'>Check Me 3</td>

      </tr>

  </table>

  <Center><input type=submit value='Test'> &nbsp &nbsp &nbsp &nbsp

                  <input type=reset value='Clear'></center>

</form>

 

 

and the associated test.php file . . .

 

 

<?php

$optiontype = $_POST['type'];

$checktype1 = $_POST['checktest1'];

$checktype2 = $_POST['checktest2'];

$checktype3 = $_POST['checktest3'];

Option: $optiontype \n

Check: $                  \n

?>

 

 

 

In this, I am assuming I need to test for "on" or "off" properties of each checktype on the

form, and then only set 'Check' to which ones the person actually checked?

 

This is confusing me greatly :)

 

 

 

checkboxes are not posted if they aren't checked... therefor

 

if (isset($_POST["checkbox1"]))

is sufficient to see if its checked

 

and for <selects>

$optiontype = $_POST['type'];

will indeed return the XXXX in <option value='XXXX'>

 

...

 

tdw

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.