Search for:
Jump to: 
Your Ad Here
Post new topic Reply to topic
Author Message
 Post subject: Generating a table dynamically and add color to each cell.
PostPosted: Wed Jun 29, 2011 1:17 pm 
Offline

Joined: Mon Nov 12, 2007 10:12 am
Posts: 355
Dear friends.

//CODE
<html>
<head>
<style type="text/css">
.topdiv{
width:100%;
height:25%;
background-color:red;
text-align:center;

}
.bodydiv{
width:100%;
height:75%;
background-color:green;
}
</style>
<script type="text/javascript">
function validate(){
var rows=document.subform.row.value;
var cols=document.subform.col.value;
if(rows=="" || isNaN(rows)){
alert("Enter a valid row number");
document.subform.row.focus();return false;
}
if(cols=="" || isNaN(cols)){
alert("Enter a valid col number");
document.subform.col.focus();return false;
}
drawTable(rows,cols);
return false;
}
function fill_color(getId){
alert(getId);
var getcolor=prompt("Enter a color","");
document.getElementById(getId).bgColor=getcolor;

}
function drawTable(row, col){
var chkloop = 1;
tabStr="<table cellspacing='2' cellpadding='15' border='2'>";
for(i=1;i<=row;i++){

tabStr +="<tr>";
for(j=1;j<=col;j++){
var as_id ='FillC'+chkloop;
tabStr +="<td id='"+as_id+"' onclick='fill_color(this.id)' >&nbsp</td>";
chkloop ++;
}
tabStr +="</tr>";
}
tabStr +="</table>";
document.getElementById("spanid").innerHTML=tabStr;


}
</script>
</head>
<body>
<div class="topdiv">
<form name="subform" method="post" onsubmit="return validate()"><br/><br/>
Enter Number of rows<input type="number" name="row" id="row" /><br/><br/>
Enter Number of cols<input type="number" name="col" id="col" /><br/><br/>
<input type="submit" value="submit" name="submit" />
</form>
</div>
<div class="bodydiv">
<span id="spanid">
</span>
</div>
</body>
</html>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic    [ 1 post ] 

1, 2, 3, 4, 5 ... 413
Recent topics  Replies   Views   Last post 
No new posts Ecommerce website development and website Design

by iweballey » Fri May 17, 2013 7:15 am in PHP-Code Help

0

91

Fri May 17, 2013 7:15 am

iweballey View the latest post

No new posts How to upgrade and migrate Joomal site

by mallikharjuna rao » Mon Jan 21, 2013 1:40 pm in Joomla

1

342

Thu May 16, 2013 9:53 am

sunitha12 View the latest post

No new posts Benefits of PHP

by hirephpexpert » Fri Sep 07, 2012 4:41 am in CakePHP

6

1565

Wed May 15, 2013 6:25 am

PrettyPrincesG View the latest post

No new posts How to stop user from getting registered in Joomla

by mallikharjuna rao » Tue Jan 22, 2013 5:16 am in Joomla

3

1463

Wed May 15, 2013 6:17 am

PrettyPrincesG View the latest post

No new posts How to write a query in social engine

by fathima_sony » Tue Sep 06, 2011 12:34 pm in Others

2

1754

Tue May 14, 2013 12:09 pm

sanath123 View the latest post


Your Ad Here