Echo only selected Checkbox value.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toushif.engg
Forum Newbie
Posts: 1
Joined: Sat Nov 27, 2010 3:56 am

Echo only selected Checkbox value.

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Echo only selected Checkbox value.

Post by Jonah Bron »

I don't quite understand your question... are you saying you want to output the value of a checkbox?
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: Echo only selected Checkbox value.

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Echo only selected Checkbox value.

Post 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']; }
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply