checkbox values

They have: 18 posts

Joined: Mar 2006

Hi,

I need to compare a php variable to a checkbox value and if they match turn that checkbox to TRUE. The checkbox values are not submitted from a form they reside on the same page as the PHP code. I'm not sure how to get the checkbox value into a PHP variable for comparison and if a match is found set the checkbox to TRUE.

Thanks

Don

relevant code:-

<?
//get nights from table.
$lNights = $lobjVenueEdit->get("fldVenueNights");

//seperate string into individual nights
$lNights = explode(",",$lNights);

foreach($lNights AS $lNight){
$lNight = trim($lNight);
//some code here which will compare $lNight
//with the checkbox values
}
?>

Sunday  

Monday  

Tuesday  

Wednesday  
Thursday  

Friday  

Saturday  

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

Well, to make a checkbox checked, you need to have the word 'checked' in the tag. For example, something like this:

<input type="checkbox" name="cbxSunday" value = "Sunday" <strong>checked </strong>/>'

...so what you could do it set a bunch of empty variables or an array and set those values to 'checked' as needed. For example:

<?php
if (condition)
{
$checked['cbxSunday'] = 'checked';
}
else
{
$checked['cbxSunday'] = '';
}
?>


<input type="checkbox" name="cbxSunday" value = "Sunday" <strong><?php echo $checked['cbxSunday'] ?></strong>/>
'

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.