Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Disable Checkbox

    Hey guys is there a way the checkbox could be disabled once its been marked? Here is the code..its supposed to be automatically marked when it reaches a certain date. I want it to be disabled when it gets marked

    PHP Code:
    <?php
     $con
    =mysqli_connect("localhost","root","","User_db");
     
    // Check connection
     
    if (mysqli_connect_errno())
       {
       echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
       }

     
    $result mysqli_query($con,"SELECT * FROM Assessments");

     echo 
    "<table class='sortable' border='0' cellpadding='40'
    cellspacing='0'>
    <thead>
     <tr>
     <th>Title</th>
     <th>Lecturer</th>
     <th>Start</th>
     <th>Due</th>
     <th>Completed</th>
     </tr>
     </thead>"
    ;

     while(
    $row mysqli_fetch_array($result))
       {
       echo 
    "<tr>";
       echo 
    "<td>" $row['Title'] . "</td>";
       echo 
    "<td>" $row['Lecturer'] . "</td>";
       echo 
    "<td>" $row['Start'] . "</td>";
       echo 
    "<td>" $row['Due'] . "</td>";
       
       echo 
    "<td>" ."<input type='checkbox' id='mycheckbox' name='Completed' value='Completed'" . (date("d/m/Y") >= $row['Due'] ? " checked='checked'" "") . " />";
       echo 
    "</tr>";
       }
     echo 
    "</table>";

     
    mysqli_close($con);
     
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    If the condition is as you have here, you simply add 'disabled="disabled"' to the ternary true.
    Although, disabled checkboxes are not considered successful. If you need to retrieve the value after a post, you'll need to use a hidden input or a session to pass the value through.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •