javascript - To apply css to the elements retrieved from database based on their value in database -


here trying do- have mysql table fields namely- clientname, urgent, complete.and displaying values fields have html table fields- clientname,urgent , complete.each row consist of clientname ,button urgent , button complete.if click on button urgent in table row button's color changes red , if again click on button again attains original color. in short,it toggles between 2 classes.at moment ,in database urgent field value gets updated 0(initial value) 1.now when reload page want display urgent button value 1 in red color.i.e. want apply css elements based on value in database. able toggle classes change color of urgent button on click , update value refresh page again attains default color.please let me know how able retain color if value in database 1 ,even if refresh page. jquery code-

$(".u").click(function () {    $(this).toggleclass("urgent");    var id = $(this).attr('id');     $.ajax({     type:"post",     url:"urgent.php",     data:{'keyid': id},     cache: false, success: function(html){  $("#clientsheet").after(html); }     });return false;  }); 

html code-

 <td style='text-align:center;'><button  id=".$row['id']." class='u'>u</button></td> 

please let me know if need more info. in advance. edited- how retrieving html table data database-

 <?php include('db.php'); $fetch= mysqli_query($conn,"select * pendingwork order clientname asc");  while($row=mysqli_fetch_array($fetch)){   $id = $row['id'];             $newname = $row['clientname'];             echo "<tr id=".$row['id']."class='edit_tr'>";               echo " <td class='edit' id=".$id." name=".$newname.">".$row['clientname']."</td>                    <td style='text-align:center;'><button  id=".$row['id']." class='u'>u</button></td>                    <td></td>                    <td  style='text-align:center;'><button id=".$row['id']." class='del'>del</button></td>             </tr>"; } 

something like:

echo " <td class='edit' id=".$id." name=".$newname.">".$row['clientname']."</td>                <td style='text-align:center;'><button  id=".$row['id']." class='".($row["urgent"] == 1 ? "class1" : "class2")."'>u</button></td>                <td></td>                <td  style='text-align:center;'><button id=".$row['id']." class='del'>del</button></td>         </tr>"; 

this bit key:

($row["urgent"] == 1 ? "class1" : "class2") 

it checks value of "urgent" , determines class use. if "urgent" 1, class1 applied, otherwise class2. replace class names appropriate application.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -