473,413 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

change of bgcolor in a td of a dynamic table using javascript and ajax

Hi,
I have a dynamic table in my programme in php and the value of a particular cell gets reduced after every 3 seconds.I want to change the bg color of that particular into a different color when it reaches '0'.Pl help me.

thanks in advance

Suguna
Dec 21 '07 #1
4 2071
Markus
6,050 Expert 4TB
Hi,
I have a dynamic table in my programme in php and the value of a particular cell gets reduced after every 3 seconds.I want to change the bg color of that particular into a different color when it reaches '0'.Pl help me.

thanks in advance

Suguna
Without the code you now have it's harder to help you because we have no idea what you're doing.

Please post the code [as much of it which is relevant] and we can help you add to it.

Good day
Dec 21 '07 #2
hi,

so have you tried out someting like this (its in javascript)
get the id of the td, for examle its td1
then
td1.style.background = "<some color>"

hope this helps you.

Hi,
I have a dynamic table in my programme in php and the value of a particular cell gets reduced after every 3 seconds.I want to change the bg color of that particular into a different color when it reaches '0'.Pl help me.

thanks in advance

Suguna
Dec 21 '07 #3
Hi,
Here is my codings.Pl help me to change the bgcolor when the value in td11
becomes 0.
[PHP]<?
session_start();
?>
[/PHP][HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />-->
<!--<meta http-equiv="refresh" content="3" />-->
<title>Live Campaign Report</title>
<link href="main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.odd{background-color:#acbdee;}
.even{background-color:#cddeff;}
</style>
</head>
<body onload="alternate('thetable')">

<div id="header"><h2><img src="images/ptlogo.gif" /></h2>
<h1><img src="images/pt1.gif" width="870px" height="120px" /></h1>
</div
><DIV id=content-wrap>
<DIV id=content>
<DIV>
<H1 class="h1">Live Campaign Report</H1></DIV>
<STYLE>A {
TEXT-DECORATION: none
}
A:hover {
TEXT-DECORATION: none
}
A:visited {
TEXT-DECORATION: none
}
A:link {
TEXT-DECORATION: none
}
</STYLE>
[/HTML]
[PHP]<?PHP
include("conn.php");
$sel= mysql_select_db("dialer");
include("function.php");

$fdate = date('d-m-Y');
$tdate = date('d-m-Y');

$tables=$_GET['tables'];

/* $fdate = $_POST['fdate'];
$tdate = $_POST['tdate'];
$submit = $_POST{'submit'};*/
?>
[/PHP]
[HTML]<body>


</div>
<DIV id=content-wrap>
<DIV id=content>

<br /><center>

<td colspan="4" align="center" >Select Campaign:
<form name="myform" method="POST" action="manage1_campaign1.php">

[/HTML][PHP]<?php
$list = mysql_list_tables ("dialer");

echo"&nbsp;&nbsp;&nbsp;<select name='tables' value=\'\' onChange='tablepick();'>";
$i = 0;
//echo "<option value=''>Select Table</option>";
if($_GET['tables'])
{
echo "<option value='$tables' selected>$tables</option>";
}
while ($i < mysql_num_rows ($list)) {
$tb_names[$i] = mysql_tablename ($list, $i);

echo"<option value='$tb_names[$i]'>$tb_names[$i]</option>";
$_SESSION['tables']=$_GET['tables'];
$i++;
}
echo "</select>";

?>
</form>
<?php

//echo $submit."<br>";
$fdate1 = explode("-",$fdate);
//print_r $fdate1;
$fdate3 = (strlen($fdate1[1]) == '1') ? "0".$fdate1[1] :$fdate1[1] ;
$fdate4 = (strlen($fdate1[0]) == '1') ? "0".$fdate1[0] :$fdate1[0] ;

$fdates = $fdate1[2]."-".$fdate3."-".$fdate4;


if($fdate == $tdate)
{
$tdates1 = mktime(0,0,0,$fdate3,$fdate4+1,$fdate1[2]);
$tdates=date("Y-m-d", $tdates1);
// echo "Tomorrow is ".$tdates;

} else{
$tdate1 = explode("-",$tdate);
$tdate3 = (strlen($tdate1[1]) == '1') ? "0".$tdate1[1] :$tdate1[1] ;
$tdate4 = (strlen($tdate1[0]) == '1') ? "0".$tdate1[0] :$tdate1[0] ;

$tdates = $tdate1[2]."-".$tdate3."-".$tdate4;
}

//echo "<table cellspacing=5 cellpadding=5 border=0 align=center><tr class=h3><td>From Date </td></tr>";


echo "<tr> <td>&nbsp;</td></tr></table>
<table border=1 width=95% align=center id='thetable'>
<tr><td class='th'>FreshRecord</td></td><td class='th'>Sale</td>
<td class='th'>CallBack</td><td class='th'>HangupAfterListen</td>
<td class='th'>AnsweringMachine</td><td class='th'> Busy</td>
<td class='th'>NotInterested</td><td class='th'>OverPhone</td>
<td class='th'>MoveAway</td><td class='th'>LanguageBarrier</td>
<td class='th'>Contact</td></tr>";

if($fdate != $tdate){

}
if ($tables=$tables)
{

$td1 = mysql_query("SELECT count(*) FROM $tables where disposition ='1'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td11 = mysql_fetch_row($td1);

$td2 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='12'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td22 = mysql_fetch_row($td2);

$td3 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='0'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td33= mysql_fetch_row($td3);

$td4 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='2'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td44 = mysql_fetch_row($td4);

$td5 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='3'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td55 = mysql_fetch_row($td5);

$td6 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='4'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td66 = mysql_fetch_row($td6);

$td7 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='5'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td77 = mysql_fetch_row($td7);

$td8 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='6'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td88 = mysql_fetch_row($td8);

$td9 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='7'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td99 = mysql_fetch_row($td9);

$td10 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='9'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td1010 = mysql_fetch_row($td10);

$td112 = mysql_query("SELECT count(*) FROM $tables where lastupdated >='$fdates' and disposition ='11'");

//$td1 = mysql_query("SELECT count(*) FROM asterisk.cdr where calldate ='$fdates' and length(src) =10 and lastapp <>'v%'");

$td1111 = mysql_fetch_row($td112);



echo "<tr>
if($td11[0]==0)
{
echo"<td bgcolor="red">$td11[0]</td>";
}
else
{
echo"<td bgcolor="green">$td11[0]</td>";
}
<td>$td22[0]</td>
<td>$td33[0]</td>
<td>$td44[0]</td>
<td>$td55[0]</td>
<td>$td66[0]</td>
<td>$td77[0]</td>
<td>$td88[0]</td>
<td>$td99[0]</td>
<td>$td1010[0]</td>
<td>$td1111[0]</td></tr>";

}


?>[/PHP]
[HTML]</td>

<tr>

</tr>

</table>
</center>
</DIV>
</DIV><br />
<div id="footer">
<hr />
<table border=0 cellspacing=0 cellpadding=0>
<tr><td align="left">
<table width="400px">
<tr>
<td><a href="live_reports.php"><img src="images/back.jpg" /></a></td>
</tr>
</table>
</td>
<td>
<table width="450px">
<tr><td align="left">&copy PeopleTech</td></tr>
</table>
</td>
<td>
<table><tr>
<td align="right"><a href="home.php"><img src="images/home.jpg" /></a></td></tr></table>
</td>
</tr>
</table>
</div>
<script language="javascript">
var sURL = unescape(window.location.pathname);
function tablepick(){
var val=document.myform.tables.value;
//document.form1.client.value = document.form1.store_id.value;
var ul =sURL +'?tables='+ val;
window.location.href =ul ;
//alert('hai');
}
function alternate(id){
if(document.getElementsByTagName){
var table = document.getElementById(id);
var rows = table.getElementsByTagName("tr");
for(i = 0; i < rows.length; i++){
//manipulate rows
if(i % 2 == 0){
rows[i].className = "even";
}else{
rows[i].className = "odd";
}
}
}
}
</script>
<script type="text/javascript">

function reFresh() {
location.reload(true)
}
window.setInterval("reFresh()",1000);

</script>
</body>
</html>[/HTML]

Suguna
Dec 21 '07 #4
acoder
16,027 Expert Mod 8TB
Why are you reloading the page every second?

You load the page once and change the td11 value every second.

Give the td which contains td11 an id, e.g. td11, then access the cell value using document.getElementById("td11").innerHTML. Then decrement by 1. This would be in your reFresh function. When it reaches 0, change the background colour using JavaScript.
Dec 22 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: kj | last post by:
Is there a way to dynamically (e.g. upon onClick) change the bgColor attribute of a table cell? I tried cell.setAttribute("bgColor", someColor), where someColor was a string of the form "#RRGGBB",...
2
by: Pete Kipe | last post by:
I'm not a JavaScript programmer...but I'm trying to put together a simple menu system for a new website and need a little help. I have the following script: <SCRIPT language=javascript> <!--...
22
by: Saul | last post by:
I have a set of radio buttons that are created dynamically, after rendered I try loop thru this set by getting the length of the set, but I keep getting an error stating the element is undefined. I...
3
by: rlueneberg | last post by:
I want to change the color of an "a" child element inside a table cell via javascript. Is there any way to do that? Ps: there is no id assigned to child elements. I would like to discover the child...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
4
by: gregincolumbus | last post by:
I am trying to get the financial calculation on this to trigger whenever there is a change to select1. Right now, the user has to click on select2 to trigger the changes. Ideally, a change of...
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories shown by differnent radio buttons, on the click of...
8
by: tuananh87vn | last post by:
i have a sample code like below: index.html <script language='javascript'> //start xmlhttprequest if (window.XMLHttpRequest) //for IE 7 & FF { request=new XMLHttpRequest(); }
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.