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

Which cell of the table was selected ?

Hi,
I have a table with four columns.

By default, except for the second column (id="s01") all column values
are protected. When a value is selected from second column, the third
column is enabled. When a value is selected in the third column, the
fourth column is enabled and a separate button for adding a new row
(as in <trof code snippet above) is also enabled.

As you would have guessed, I have got the javascript code working when
number of rows is one.
This is obviously because, the javascript for en/disablement does not
get to know which cell was selected.

Thus, if there are four rows and I selected a value from the second
column (id="s02"), how do I detect which cell was selected and thereby
take the action in the adjacent cell ?
<table id="t01" cellpadding="1" cellspacing="0">
<tr>
<td align=center>Delete</td>
<td align=center>Item type</td>
<td align=center>Month Ending</td>
<td align=center>Comments</td>
</tr>
<tr><td><input type="checkbox" id="c01" disabled="true"></td>
<td><select id="s01" value="0">
<option id="00" value="0">Select item type...</option>
<option id="01" value="1">Vendor Item</option>
<option id="02" value="2">Wholesale Item</option>
<option id="03" value="3">Distributor Item</option>
</select></td>
<td><select id="s02" disabled="true" value="0">
<option id="00" value="0">Month ending...</option>
<option id="01" value="1">Jan</option>
<option id="02" value="2">Feb</option>
<option id="03" value="3">Mar</option>
</select></td>
<td><input type="text" id="desc" size="80" accept="plain/text"
disabled="true"></input></td>
</tr>
</table>

Thanks,
Nagesh

PS: I did search this forum. But, most code samples pointed to getting
to a cell from the javascript code rather than the other way around.

Jun 10 '07 #1
2 2549
ASM
cogitoergosum a écrit :
>
<table id="t01" cellpadding="1" cellspacing="0">
<tr>
<td align=center>Delete</td>
<td align=center>Item type</td>
<td align=center>Month Ending</td>
<td align=center>Comments</td>
</tr>
<tr><td><input type="checkbox" id="c01" disabled="true"></td>
<td><select id="s01" value="0">
value is not allowed in a tag 'select'
<option id="00" value="0">Select item type...</option>
an id (as a name) can't begin with a number
the 1st character must be a letter
<option id="01" value="1">Vendor Item</option>
<option id="02" value="2">Wholesale Item</option>
<option id="03" value="3">Distributor Item</option>
</select></td>
<td><select id="s02" disabled="true" value="0">
<option id="00" value="0">Month ending...</option>

only ONE id with same name is allowed !
<option id="01" value="1">Jan</option>
<option id="02" value="2">Feb</option>
<option id="03" value="3">Mar</option>
</select></td>
<td><input type="text" id="desc" size="80" accept="plain/text"
disabled="true"></input></td>
</tr>
</table>

Thanks,
Nagesh

PS: I did search this forum. But, most code samples pointed to getting
to a cell from the javascript code rather than the other way around.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Untitled</title>
<script type="text/javascript">
<!--

function nextFree(what) {
var idx;
// collection of elements in what's row
var rw = setElem(what);
// index in row
switch(what.name) {
case 's1[]': idx = 2; break;
case 's2[]': idx = 3; break;
case 'desc[]': idx = 0; break;
}
if(what.checked) {
rw[1].selectedIndex = rw[2].selectedIndex = 0;
rw[3].value ='';
rw[0].disabled = rw[2].disabled = rw[3].disabled = true;
what.checked = false;
}
else
if(1<idx && idx<4) {
if(what.selectedIndex==0) {
rw[0].disabled = rw[idx].disabled = true;
if(idx==2) {
rw[idx].selectedIndex = 0;
rw[3].disabled = true;
}
rw[3].value = '';
alert('you must choice an item in this list');
}
else rw[idx].disabled=false;
}
else
rw[0].disabled=false;
}

function setElem(where) {
// which table row ?
while(where.tagName.toLowerCase() != 'tr')
{
where = where.parentNode;
}
var I = where.getElementsByTagName('INPUT');
var S = where.getElementsByTagName('SELECT');
// array of form elements in this table's row
var rw = [I[0], S[0], S[1], I[1]];
return rw;
}

onload = function() {
var t = document.getElementById('t01');
t = t.getElementsByTagName('TR');
for(var i=1; i<t.length; i++) {
var I = t[i].getElementsByTagName('INPUT');
var S = t[i].getElementsByTagName('SELECT');
I[0].onclick = function() { nextFree(this); };
I[1].onchange = function() { nextFree(this); };
S[0].onchange = function() { nextFree(this); };
S[1].onchange = function() { nextFree(this); };
}
}
//-->
</script>
</head>
<body>
<form action="javascript:void();">
<table id="t01" cellpadding="1" cellspacing="0">
<tr>
<td align=center>Delete</td>
<td align=center>Item type</td>
<td align=center>Month Ending</td>
<td align=center>Comments</td>
</tr>
<tr><td><input type="checkbox" id="c_01" name="c1[]"
disabled="true"></td>
<td><select id="s1_01" name="s1[]">
<option value="0">Select item type...</option>
<option value="1">Vendor Item</option>
<option value="2">Wholesale Item</option>
<option value="3">Distributor Item</option>
</select></td>
<td><select id="s2_01" name="s2[]" disabled="true">
<option value="0">Month ending...</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
</select></td>
<td><input type="text" id="desc_01" name="desc[]" size="80"
accept="plain/text" disabled="true"/></td>
</tr>
<tr><td><input type="checkbox" id="c_02" name="c1[]"
disabled="true"></td>
<td><select id="s1_02" name="s1[]">
<option value="0">Select item type...</option>
<option value="1">Vendor Item</option>
<option value="2">Wholesale Item</option>
<option value="3">Distributor Item</option>
</select></td>
<td><select id="s2_02" name="s2[]" disabled="true">
<option value="0">Month ending...</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
</select></td>
<td><input type="text" id="desc_02" name="desc[]" size="80"
accept="plain/text" disabled="true"/></td>
</tr>
<tr><td><input type="checkbox" id="c_03" name="c1[]"
disabled="true"></td>
<td><select id="s1_03" name="s1[]">
<option value="0">Select item type...</option>
<option value="1">Vendor Item</option>
<option value="2">Wholesale Item</option>
<option value="3">Distributor Item</option>
</select></td>
<td><select id="s2_03" name="s2[]" disabled="true">
<option value="0">Month ending...</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
</select></td>
<td><input type="text" id="desc_03" name="desc[]" size="80"
accept="plain/text" disabled="true"/></td>
</tr>
</table>
</form>
</body>
</html>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jun 10 '07 #2
Merci, Monsieur !

Regards,
Nags

Jun 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dom Nicholas | last post by:
Hi, I have a table (inside a form) that is dynamically created ie the user can add / remove rows dynamically. Each table row has 4 columns : a selection pull down list a text field for...
5
by: Randy | last post by:
Hello, Can someone tell me how you de-select (un select) the currently selected cell in a datagrid? Thanks
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
2
by: Bass Pro | last post by:
How do I access a textbox when it was added to a table cell? I've tried using the findcontrol function with no result. I create it as such... Dim myTable As Table = New Table Dim Row as...
7
by: Arne Beruldsen | last post by:
in vbnet2005 I have a datagridview. When the user clicks on a row...I would like the contents of certain cells to populate a textbox. To do this...i need to be able to refer to the row and...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi, I can return the rowindex using SelectedRow or SelectedIndex But, how do I get my code to return the cell or column index of a selected row in my gridview? thanx -- Regards,
0
by: xprimus | last post by:
Can anyone help me with this, I have a linked image in a tale cell and whenever I click on the image it expands, not only that I have to click on it again to get the link to go. These are the...
1
by: Manil | last post by:
I usually have no problem with Firefox, but here is a rare instance of IE displaying a table with image slices correctly and Firefox adding space where I seemingly have none. Is there anything I can...
3
Frinavale
by: Frinavale | last post by:
Hi there, I'm using JavaScript to highlight a row or column in a table. I have created a CSS class that changes the background colour to a light blue and I apply this class to the cells in the...
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: 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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.