javascript/ php/ jquery/ css3

I have a looped table displaying the results of a drop-down form post (lotstatus). I want to be able to change the color of the text based on the value they selected in the form .

 if($result = mysqli_query($conn, $sql)){ if(mysqli_num_rows($res) > 0){ echo " <table class='table table-bordered table-striped' width='100%' data-pagination='true' data-search='true'>"; echo " <thead>"; echo " <tr>"; echo " <th>Status</th>"; echo " <th>Street #</th>"; echo " <th>Street Name</th>"; echo " <th>City</th>"; echo " <th>Parcel ID</th>"; echo " <th>Lot # (Unit)</th>"; echo " <th>Contract Signed Date</th>"; echo " <th>Closing Date</th>"; echo " <th>Action</th>"; echo "</tr>"; echo "</thead>"; echo " <tbody>"; while($row = mysqli_fetch_array($res)){ echo " <tr>"; echo " <td>" . " <div class='statuscolor'>". $row['lotstatus'] . "</div>". "</td>"; echo " <td>" . $row['streetnumber'] . "</td>"; echo " <td>" . $row['streetname'] . "</td>"; echo " <td>" . $row['city'] . "</td>"; echo " <td>" . $row['parcelid'] . "</td>"; echo " <td>" . $row['lotnumber'] . "</td>"; echo " <td>" . $row['contractsigneddate'] . "</td>"; echo " <td>" . $row['closingdate'] . "</td>"; echo " <td>"; echo "<a class='btn btn-info mr-2 mt-2' href='readLot.php?id=". $row[' id '] ."' title='View' data-toggle='tooltip'><span style='margin-left: 7px;' class='la la-file-o ks-icon'></span></a>"; echo "<a class='btn btn-warning mr-2 mt-2' href='updateLot.php?id=". $row[' id '] ."' title='Edit ' data-toggle='tooltip'><span style='margin-left: 7px;' class='la la-pencil ks-icon'></span></a>"; echo " <a class='btn btn-danger mt-2' href='deleteLot.php?id=". $row[' id '] ."' title='Delete ' data-toggle='tooltip'><span style='margin-left: 7px;' class='la la-close ks-icon'></span></a>"; echo "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; // Free result set mysqli_free_result($result); } else{ echo " <p class='lead'><em>No Lots were found.</em></p>"; } } 

Here in the form I'm using: The user selects lot status - I want to change the color of the status based on what they chose.

 <select class="form-control" value="<?php echo $lotstatus; ?>" id="lotstatus" name="lotstatus"> <option value="NA">N/A</option> <option value="Executed">Executed</option> <option value="Not Interested">Not Interested</option> <option value="Hold">Hold</option> <option value="Title Ordered">Title Ordered</option> <option value="Vetting">Vetting</option> <option value="Survey Ordered">Survey Ordered</option> <option value="Lean Search Ordered">Lean Search Ordered</option> <option value="Clear to Close">Clear to Close</option> <option value="Closed">Closed</option> </select> 

I've tried styling the option value and also tried selecting the text() value of the field. Nothing is working... HELP!

First you need to add each row the status:

<tr class=\"Executed\">"; echo "
<tr class=\"Hold\">"; echo "

With JS you can add to the parent <table> the selected status:

$('select#lotstatus').on('change', function() {
  $('table').attr('status', $(this).val());
});

Then, in your css you need to set the color that you want for each status:

table[status="Executed"] tr.Executed .statuscolor { color: red; }
table[status="Hold"] tr.Hold .statuscolor { color: green; }
table[status="Closed"] tr.Closed .statuscolor { color: yellow; }

Maybe you need to add an "id" to the table to avoid interferences with other tables.

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question i want to change the text color based on the condition Change Text And Background Color Of Table Cell Based On Text Value how to change the text color of a table cell based on value I want to change color within the value text shown in the text area. such as shown in the image Change text color based on value with developer console Dynamically change the color or text based on value with Javascript Change text color based on td value Ajax - change text color based on return value How to change the text color based on the text value inside a paragraph How to change color of text based on text-value by using css?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM