...

View Full Version : Calling a page element from a string.



Javanic99
12-27-2005, 07:47 PM
Hi,

I haven't done any Javascript for a few years now but I'm sure I have found a way around this before.

I have a table containing values. One of the TDs in each row has an input box so that users can input a value. When this changes I want to recalculate some of the other TDs in that row.

I can get the row number from string manipulation of the input box source element ID. I then want to write back to the table using a row and column id name built from this ID.

how do I use my new string so that I can assign a value to the page object of the same name?

Thanks,

Nick

Kor
12-28-2005, 10:21 AM
Something like this?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function calculate(inp){
var cells = inp.parentNode.parentNode.getElementsByTagName('td');
cells[4].firstChild.data = Number(inp.value)+Number(cells[2].firstChild.data)
}
</script>
</head>
<body>
<table width="250" border="0" cellspacing="2" cellpadding="2">
<tr>
<td> <input name="textfield" type="text" size="5" onkeyup="calculate(this)"> </td>
<td>+</td>
<td>10</td>
<td>=</td>
<td>10</td>
</tr>
<tr>
<td> <input name="textfield" type="text" size="5" onkeyup="calculate(this)"> </td>
<td>+</td>
<td>20</td>
<td>=</td>
<td>20</td>
</tr>
<tr>
<td> <input name="textfield" type="text" size="5" onkeyup="calculate(this)"> </td>
<td>+</td>
<td>30</td>
<td>=</td>
<td>30</td>
</tr>
</table>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum