...

View Full Version : Need help with JS- dynamic table cell entry



writetoamrutha
11-21-2010, 11:01 AM
<script language="javascript">
function splitNumber()
{alert("inside splitnumber");

var x = parseInt(document.getElementById("value1").value);
var z = x%10; /*units*/
var y = (x - z)/10; /*tens*/
var c = parseInt(document.getElementById("value3").value);
var a = c%10; /*units*/
var b = (c - a)/10; /*tens*/


for(var i=0;i<=z;i++)
{
var parseInt(document.getElementById("u1").td.value);
for(((document.getElementById("u1").td.value))=0;((document.getElementById("u1").td.value))<=i;((document.getElementById("u1").td.value))++)
{
document.write("<td> " +document.getElementById("u1").td.value +"</td>")
}
}
}
</script>



/*this is the code i write for generating unique values in the table cells, but it is not working*/




<body >

<div class="left">
<table class="main" cellpadding="3px" cellspacing="6px">

<tr>
<td width="630px" height="50px" bgcolor="#ffffff">
<table class="tens">
<tr id="t1">
<td value="9"></td>
<td value="8"></td>
<td value="7"></td>
<td value="6"></td>
<td value="5"></td>
<td value="4"></td>
<td value="3"></td>
<td value="2"></td>
<td value="1"></td>
</tr>
</table>
</td>
<td width="200px" height="50px" bgcolor="#ffffff">
<table class="units">
<tr id="u1">
<td value="9"></td>
<td value="8"></td>
<td value="7"></td>
<td value="6"></td>
<td value="5"></td>
<td value="4"></td>
<td value="3"></td>
<td value="2"></td>
<td value="1"></td>
</tr>
</table>
</td>
</tr>

<tr>
<td width="630px" height="50px" bgcolor="#ffffff">
<table class="tens">
<tr id="t2">
<td value="9"></td>
<td value="8"></td>
<td value="7"></td>
<td value="6"></td>
<td value="5"></td>
<td value="4"></td>
<td value="3"></td>
<td value="2"></td>
<td value="1"></td>
</tr>
</table>
</td>
<td width="200px" height="50px" bgcolor="#ffffff">
<table class="units">
<tr id="u2">
<td value="9"></td>
<td value="8"></td>
<td value="7"></td>
<td value="6"></td>
<td value="5"></td>
<td value="4"></td>
<td value="3"></td>
<td value="2"></td>
<td value="1"></td>
</tr>
</table>
</td>

</tr>
<tr>
<td width="630px" height="50px" bgcolor="#ffffff">
<table class="tens">
<tr id="t3">
<td value="9">9</td>
<td value="8">8</td>
<td value="7">7</td>
<td value="6">6</td>
<td value="5">5</td>
<td value="4">4</td>
<td value="3">3</td>
<td value="2">2</td>
<td value="1">1</td>

</tr>
</table>
</td>
<td width="200px" height="50px" bgcolor="#ffffff">
<table class="units">
<tr id="u3">
<td value="9">9</td>
<td value="8">8</td>
<td value="7">7</td>
<td value="6">6</td>
<td value="5">5</td>
<td value="4">4</td>
<td value="3">3</td>
<td value="2">2</td>
<td value="1">1</td>

</tr>
</table>
</td>

</tr>
</table>



</div>
<div class="right" >
<table cellpadding="3px">
<tr>
<td width="5px"></td>
<td><span class="row"><input min="0" max="99" type="number" id="value1" name="value1" value="0" onchange="javascript:addNumbers()"/></span></td>
</tr>
<tr>
<td width="5px"><b style="font-size:25px; position:relative; top:18px;">+</b></td>
<td><span class="row"><input min="0" max="99" type="number" id="value3" name="value3" value="0" onchange="javascript:addNumbers()"/></span></td></tr>
<tr><td width="5px"></td>
<td><span class="row" ><input style=" width:66px; position:relative; right:25px;" readonly="readonly" id="answer" name="answer" value="0" /></span></td></tr>
</table>





</div>
</body>

Philip M
11-21-2010, 01:02 PM
When posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.

See also http://www.codingforums.com/showthread.php?t=2090 Para 3. What exactly is your problem?


You don't seem to understand how to create a table. A <tr> cannot have a "value".


<table>
<tr id="t2">
<tr height="50px" bgcolor="#ffffff">
<td width = "100px">XXX</td>
<td width = "100px"> YYY</td>
<td width = "100px"> ZZZ</td>
</tr>
</table>

"He was a wonderful man, as was his wife." - Sports Commentator



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum