Thread: Checkbox Toggle

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Exclamation Checkbox Toggle


    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 id='Due'>" $row['Due'] . "</td>"
       echo 
    "<td>" ."<input type='checkbox' id='mycheckbox' name='Completed' value='Completed' />"
       echo 
    "</tr>"
       } 
     echo 
    "</table>"

     
    mysqli_close($con); 
     
    ?>
    Hello guys I was wondering if the checkbox would get check when the date on $row['Due'] is reached for example 14/04/2013 is the date on Srow['Due']. The checkbox should automatically get the date and check the checkbox permanently.
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Right now it will not. Because there's no code to do anything like that.
    If you want it to (sounds reasonable) then you need code something like
    PHP Code:
    echo "<td>" ."<input type='checkbox' id='mycheckbox' name='Completed' value='Completed'" . (/* past due */ " checked='checked'" "") . " />"
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by requinix
    Right now it will not. Because there's no code to do anything like that.
    If you want it to (sounds reasonable) then you need code something like
    PHP Code:
    echo "<td>" ."<input type='checkbox' id='mycheckbox' name='Completed' value='Completed'" . (/* past due */ " checked='checked'" "") . " />"
    OMG it worked! thanx.. how could it make the checkbox disabled after it has been checked?
  6. #4
  7. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Please don't. What if I accidentally check it? What if I think it's complete, check it, doubt myself, and find out it isn't?

    Sounds like you should turn this into a "Complete" action. Like with a button. Clicking the button submits the form and marks the thing as complete.

IMN logo majestic logo threadwatch logo seochat tools logo