Page 1 of 1

problem with check boxes

Posted: Mon Aug 11, 2008 12:47 am
by susrisha
I am trying to test a html check box selected option..

I have a html page with about 6 checkboxes and the action page will have to access all the parameters which are checked and i need to display them..

Here is the initial page code :

***** PLEASE USE THE

Code: Select all

OR

Code: Select all

TAGS *****[/color]

Code: Select all

//total in html
<html>
<head>
</head>
<title> learn checkbox </title>
 
<body>
<form action= "checkbox2.php" method="post">
 
<input type="checkbox" name="option1" value ="Check1" >Check1 <br />
<input type="checkbox" name="option2" value ="Check2" >Check2 <br />
<input type="checkbox" name="option3" value ="Check3" >Check3 <br />
<input type="checkbox" name="option4" value ="Check4" >Check4 <br />
<input type="checkbox" name="option5" value ="Check5" >Check5 <br />
<input type="checkbox" name="option6" value ="Check6" >Check6 <br />
 
<input type = "submit" value= "submit" />
 
</form>
</body>
 
</html>
 
//first page code ended here

Now the action script for the code ie.,checkbox2.php

Code: Select all

//checkbox2.php starts here
<?php
 
for($i=1;$i<7;$i++)
{
$option[$i]= $_POST['option$i'];
 
}
 
for($i=1;$i<7;$i++)
{
echo $option[$i];
}
?>
//checkbox2.php ends here...
Now i dont get any out put.. it only shows a blank page.
if i type:
echo $option1 and if option1 of the main page is selected, it shows the output..
But if i try to put it in a loop, i am not getting any output.
Can someone help me in this regard..

problem with check boxes

Posted: Mon Aug 11, 2008 1:17 am
by susrisha
yaa figured it out myself

Code: Select all

 
$option[$i]= $_POST["option$i"];
 
 
 

Re: problem with check boxes

Posted: Mon Aug 11, 2008 10:20 am
by dajawu
Why don't you just change the name of the checkboxes to option[1]..[2]... instead of writing a line of code to fix an error in your code? Its a quick hack that you should fix now