views:

163

answers:

2

I have iterated a table based on my query result... I have a column lastDate it contains a date value like 01/24/2010... Now i have to check the date value with the current date if currentdate is less than or equal to lastDate i have to enable the checkbox else disable it..... Any suggestion how it can be done in php...

Here is my code

 <? if(isset($comment))
 { echo '<tr><td class=table_label colspan=5>'.$comment.'</td></tr>'; } ?>
 <?php foreach($getassignmentdata as $row) { ?>
  <td align="center" class="table_label" id="txtsubdat">
   <? 
   $dd=$row['dDate'];
   if($dd=='')
   {

   }
   else
   {
   $str = $dd;
   $dd = strtotime  ( $str );
   echo date ( 'm/d/Y' , $dd );
       }  ?>
 </td>

 <td align="center">
  <input type="checkbox" name="group" id="group" 
   value="<?=$row['dAssignment_id']?>"  onclick="checkdisplay(this);"> 
</td>

<? } ?>
A: 

In HTML, you can disable a checkbox using the disabled attribute.

<input type="checkbox" disabled>

In PHP, you can control HTML output dynamically using embedded scripts.

<input type="checkbox" <?php if (somecondition) echo 'disabled'; ?>>

This will print the disabled attribute whenever somecondition evaluates true.

BalusC
@BalusC How will i get the `lastdate` value in the condition for checkbox...
udaya
Just the usual PHP way. By `$row['lastdate']` maybe?
BalusC
+1  A: 

i tried this and it worked..

<input type="checkbox" name="group" id="group" value="<?=$row['dAssignment_id']?>" 
                <?php 
                $dd=$row['dDate'];
                if($dd=='')
                {

                }
                else
                {
                $str = $dd;
                $dd = strtotime  ( $str );
                    if((date('m/d/Y')) <= (date('m/d/Y',$dd)))
                    {
                       echo 'enabled';
                    }
                     else
                     {
                       echo 'disabled';
                     }
                }

                 ?> onclick="checkdisplay(this);"> 
udaya
You should have posted this as an update of the question and upvoted/accepted the *actual* answer. You can also just leave it all away and post a comment like "Thanks, it works now!" or so. The answer is namely already obvious enough :)
BalusC