473,385 Members | 1,341 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,385 software developers and data experts.

creating dynamic table...

hi all,
i hav created a dynamic table in javascript with no. of rows and col. being entered by the user. i hav given a mouseover event on each cell as red color and mouseout event as yellow color,


now my prob starts here. as i click any cell in the table red color appears and wen i go to the next cell previous becomes yellow and current cell becomes red but i want as i go to the third cell(any location), only the previos cell has mouseout effect (i.e yellow color) rest visited cells becomes normal (i.e white) as it is. and current cell will show the mouseover effect(i.e red color in my case)plz tell me how can it be done. your support will be appreciated and do try to reply as soon as possibl.its urgent.
thanks
Nov 30 '07 #1
2 1617
gits
5,390 Expert Mod 4TB
hi ...

please post the code (example) you have so far ... so that we may have a closer look at it

kind regards
Nov 30 '07 #2
guys so far i hav this much code done . and i need your further assistance

[HTML]<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Dynamic Table</title>
<meta name="Author" content="Chandra Vedantham">
<meta name="Description" content="Html Page">
<script>
var DEFAULT_WIDTH = 100;
var DEFAULT_HEIGHT = 100;
var tmpCell=null;
var tmprow=null;
function CreateTable(rowCount, colCount, srcHolder)
{
if(IsValidNumber(rowCount) && IsValidNumber(colCount) && (srcHolder != null) && (srcHolder.canHaveChildren))
{
srcHolder.innerHTML = "";
srcTable = document.createElement("table");
srcTable.border = 1;
srcTable.borderColor = "Black";
srcTable.height = DEFAULT_HEIGHT;
srcTable.width = DEFAULT_WIDTH;
tmpRow = null;
tmpCell = null;
srcHolder.appendChild(srcTable);

for(i=0; i<parseInt(rowCount)+1; i++)
{
tmpRow = AppendRow(srcTable)

for(j=0; j<parseInt(colCount)+1; j++)
{
tmpCell = AppendCell(tmpRow);
tmpCell .innerText=i+','+j;
tmpCell.id = i+','+j;
aa=tmpCell.id;
if(i==0 || j==0)
{
GetIndex= i+','+j;
TempSp=GetIndex.split(',');
Sp1=TempSp[0];
Sp2=TempSp[1];
srcTable.rows[0].cells[Sp2].innerText=Sp2;
srcTable.rows[Sp1].cells[0].innerText=Sp1;
}
else
{
tmpCell.onmouseover = function()
{

OnMouseOv(srcTable,tmpRow,this,rowCount,colCount);
//alert("Sp1.."+Sp1);
//alert("Sp2.."+Sp2);
}

tmpCell.onmouseout=function()
{

OnMouseOuts(srcTable,tmpRow,this,rowCount,colCount );
}
}
tmpCell = null;
}
}
tmpRow = null;
}
}

function AppendRow(srcTable)
{
if(srcTable != null)
{
return srcTable.insertRow();
}
else
{
alert("Error while creating table. Cause: Container Table is null!");
}
}

function AppendCell(srcRow)
{
if(srcRow != null)
{
return srcRow.insertCell();
}
else
{
alert("Error while creating table. Cause: Container row is null!");
}
}

function IsValidNumber(ipNum)
{
if(isNaN(ipNum))
{
alert("Invalid Number!");
return false;
}
else if(ipNum < 1)
{
alert("Number should be greater than 0!");
return false;
}
else
{
return true;
}
}
function OnMouseOv(srcTable,tmpRow,tmpCell,NoRows,NoCols)
{

tmpCell.style.fontSize ="20";
tmpCell.style.backgroundColor="red"

var TempSp=tmpCell.id.split(',');

Sp1=TempSp[0];
Sp2=TempSp[1];

//To clear the color of the Table cells
ClearColor(srcTable,NoRows,NoCols);
//Sets the Color of First cell of Row and Column To Green
srcTable.rows[Sp1].cells[0].style.backgroundColor ="Green";
srcTable.rows[0].cells[Sp2].style.backgroundColor ="Green";
}
index=0;
function OnMouseOuts(srcTable,tmpRow,tmpCell,NoRows,NoCols)
{
tmpCell.style.fontSize ="";
if(index==0)
{
prev_n=Sp1;
prev_m=Sp2;
srcTable.rows[Sp1].cells[Sp2].style.backgroundColor ="yellow";
index++;
}
else if(index==1)
{
srcTable.rows[Sp1].cells[Sp2].style.backgroundColor ="yellow";
srcTable.rows[prev_n].cells[prev_m].style.backgroundColor ="white";
prev1_n=Sp1;
prev2_m=Sp2;
index=2;
}
else if(index==2)
{
srcTable.rows[Sp1].cells[Sp2].style.backgroundColor ="yellow";
srcTable.rows[prev1_n].cells[prev2_m].style.backgroundColor ="white";
prev_n=Sp1;
prev_m=Sp2;
index=1;
}
ClearColor(srcTable,NoRows,NoCols);

}

function ClearColor(srcTable,NoRows,NoCols)
{
//alert("clear");
var i = 0;
var j = 0;

for( i=0;i<parseInt(NoRows)+1;i++)
{
srcTable.rows[i].cells[0].style.backgroundColor = 'white';
}
for( j=0;j<parseInt(NoCols)+1;j++)
{
srcTable.rows[0].cells[j].style.backgroundColor = 'white';
}


}



</script>
</head>
<body>
<table>
<tr>
<td>No. Of Rows: </td>
<td><input type=text id="txtRows" name=txtRows1 /></td>
</tr>
<tr>
<td>No. Of Columns: </td>
<td><input id="txtCols" type=text name=txtCols1 /> </td>
</tr>
<tr>
<td colspan=2 align=right><input type=button name=cmdCreate
value="Create Table" onClick="CreateTable(txtRows.value, txtCols.value,
divHolder)" /></td>
</tr>
</table>
<div id=divHolder>

</div>
</body>
</html>[/HTML]
Dec 3 '07 #3

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

Similar topics

5
by: Billy Cormic | last post by:
Hello, I am interested in dynamically creating temp tables using a variable in MS SQL Server 2000. For example: DECLARE @l_personsUID int select @l_personsUID = 9842
0
by: Ex-Em-El | last post by:
I have a problem in creating a dynamic table in the same xml : 1.xml: <?xml version="1.0" standalone="yes"?> <?xml-stylesheet type="text/xsl" href="2.xsl"?> <aaa...
2
by: Kevin | last post by:
When I declare a cursor,I use a variable to replace the sql statement: DECLARE rs CURSOR LOCAL FAST_FORWARD FOR @sqlPlan But it is not true.Who can correct for me. Another question is : How to...
13
by: Nagib Abi Fadel | last post by:
Is it possible to create a session variable for each user in Postresql ?? Thx
16
by: pukivruki | last post by:
hi, I wish to create a temporary table who's name is dynamic based on the argument. ALTER PROCEDURE . @PID1 VARCHAR(50), @PID2 VARCHAR(50), @TICKET VARCHAR(20)
10
by: jflash | last post by:
Hello all, I feel dumb having to ask this question in the first place, but I just can not figure it out. I am wanting to set my site up using dynamic urls (I'm assuming that's what they're...
0
by: Dhanasekaran B | last post by:
Dear I need to create dynamic temproray table for reporting purpose.I did't have permission for DDL commands. Without Database Administrator permission, i need to create temp. Dynamic table. (or)...
3
by: Jeff Kish | last post by:
Hi. I am between beginner and intermediate level of knowledge of sql server. I am dealing with an sql server 2005 situation (oracle also but thats another thread/story). I need to assemble a...
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
2
by: yomadhu | last post by:
I created a dynamic form in javascript. Am unable to get those values in to php to display. I need all details. If i add 10 rows the i need to display those all values. Can any one help me for that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.