Reputation: 209
I am trying to develop my website. There is a table that I made in as a button. I get the value of the button with JavaScript like this:
<script>
function setvalue(values) {
document.getElementById('posisi').value = values;
}
</script>
HTML of my table:
<table width="1023" height="248" 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><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="A1.4" /></td>
<td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="A1.8" /></td>
<td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="A2.4" /></td>
<td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="A2.8" /></td>
<td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" value="A3.4" /></td>
<td><div align="center"><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 try to manipulate background colour with this JavaScript:
<script type="text/javascript">
var htmlobjek;
$(document).ready(function(){
var pid = "document.getElementById('posisi').value = values";
$.ajax({
url: "cek.php",
data: "pid="+posisi,
cache: false,
success: function(data) {
My algorithm when my SQL success in cek.php I will call back and display in current page to manipulate the table background colour.
In cek.php my SQL like this:
SELECT ..
FROM..
WHERE posisi='S_POST[posisi]'
I will count the result (use this mssql_num_row(sql)
). If the result has a value, the background colour of the table will be red. If not, it will be green. This is what makes me confused. Any idea for my website? I hope you understand what I mean.
Upvotes: 0
Views: 300
Reputation: 2632
var ajaxCall = $.ajax({
url: "cek.php",
type:'POST',
data: {"data": i},
cache: false,
}).done( function (data) {
$("#cek").val(data);
}).fail( function () {
alert('I can not send ajax here');
});
// Now anywhere in your script:
ajaxCall.done( function (data) {
var k = $("#cek").val();
// You can now even do:
// var k = data;
if(k == "0"){
$(".data").css("background-color", "#00CC00");//green
}
else {
$(".data").css("background-color", "#FF0000");//red
}
});
Upvotes: 1
Reputation: 1868
you should use success function like this...
success: function()
{
if(rsp.success)
{
set rsp
as background colour here
}
}
Upvotes: 2