php - Changing table background color through AJAX jquery? -
scenario: when web page load automatically search cell has been input user , have value. if has been input table background color red else green.
assume table has not been input yet. table background green
and source-code of table:
<table width="1023" height="200" border="1"> <tr> <th colspan="2" scope="col">a1</th> <th colspan="2" scope="col">a2</th> <th colspan="2" scope="col">a3</th> </tr> <tr> <td bgcolor="#00cc00"><div class="data" align="center" value="a1.4"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="a1.4" /></td> <td bgcolor="#00cc00"><div class="data" align="center" value="a1.8"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="a1.8" /></td> <td bgcolor="#00cc00"><div class="data" align="center" value="a2.4"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="a2.4" /></td> <td bgcolor="#00cc00"><div class="data" align="center" value="a2.8"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="a2.8" /></td> <td bgcolor="#00cc00"><div class="data" align="center" value="a3.4"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="a3.4" /></td> <td bgcolor="#00cc00"><div class="data" align="center" value="a3.8"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="a3.8" /></td> </tr> </table>
i use ajax.jquery check cell value this
var htmlobjek; $(document).ready(function () { var = $("td").find("td.data").val(); $.ajax({ url: "cek.php", data: "i", cache: false, success: function (data) { $("#cek").val(data); } }); });
of course in cek.php this
<?php $posisi = $_post[i]; $val = mssql_num_rows(mssql_query("select*from tbltrnproduct posisi = '$posisi'")); echo"$val"; ?>
to output of cek.php. use little trick. make
<input id="cek" name="cek" type="text" />
as mirror.
after manipulate table background javascript
$(document).ready(function () { $("#cek").change(function () { var cek = $("#cek").val(); if (cek === 0) { $("td").style("bgcolor", "#00cc00");//green else { $("td").style("bgcolor", "#ff0000");//red } } }); });
but nothing happen after user input data popup form. idea can problem example more appreciate.
the brackets on if-else aren't right, it's else inside if:
if (cek === 0) { $("td").style("bgcolor", "#00cc00");//green else { $("td").style("bgcolor", "#ff0000");//red } }
i think mean
if (cek === 0) { $("td").style("bgcolor", "#00cc00");//green } else { $("td").style("bgcolor", "#ff0000");//red }
Comments
Post a Comment