Page 1 of 1

Echo only selected Checkbox value.

Posted: Wed Dec 22, 2010 11:30 pm
by toushif.engg
Hello sir,
pls help me,
i want to echo only the selected checkbox value with single value of field2 when i click on submit button ,for example

field1 field2
............ ..........
chkbx1 20
chkbx2 10
chkbx3 15
submit

i have try if cond statement and foreach loop but its not working,pls reply me how to echo

Re: Echo only selected Checkbox value.

Posted: Wed Dec 22, 2010 11:40 pm
by Jonah Bron
I don't quite understand your question... are you saying you want to output the value of a checkbox?

Re: Echo only selected Checkbox value.

Posted: Wed Dec 22, 2010 11:52 pm
by shafiq2626
Hi1
You can use this condition

Code: Select all

if($_POST['check1']=='on'){ echo $_POST['check1']; }

if($_POST['check2']=='on'){ echo $_POST['check2']; }

if($_POST['check3']=='on'){ echo $_POST['check3']; }
Please check

Re: Echo only selected Checkbox value.

Posted: Thu Dec 23, 2010 1:01 am
by social_experiment
toushif.engg wrote:i have try if cond statement and foreach loop but its not working,pls reply me how to echo
Foreach will only work with an array. Paste the html code for your form :)

Code: Select all

<?php 
 // if the checkbox is ticked / checked you can check for this
 // with isset()
 if( isset($_POST['checkbox1']) ) { echo $_POST['checkbox1']; }
?>