File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes disabling and enabling input fields in a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "disabling and enabling input fields in a table" Watch "disabling and enabling input fields in a table" New topic

disabling and enabling input fields in a table

Daniel Conner
Ranch Hand

Joined: Jan 25, 2007
Posts: 47
I have an editable table with many different input fields.. I use a checkboxes for row selection. I have all of the fields disabled. The want the fields in a particular row to be enabled when that row is selected. Right now I have an onclick event calling a function to the enable the row when selected... The problem that I have is that only the first row is being enabled. Here is a snippet from my html:

<input type="checkbox" name="tableRowId" id="sid"
value="<c ut value='${}' />"

<display:column title="Desc." sortable="true">
<input type="text" name="description"
value="<c ut value='${logmgmt.description}' />"
id="txtDescription" disabled="true" />

<display:column title="Weight" sortable="true">
<input type="text" name="weight"
value="<c ut value='${logmgmt.weight}' />"
id="txtWeight" disabled="true" />

<display:column title="Cost" sortable="true">
<input type="text" name="cost"
value="<c ut value='${logmgmt.cost}' />"
id="txtCost" disabled="true" />

Here is my enableRows function:

function enableRows() {
var description = document.getElementById("txtDescription");
var weight = document.getElementById("txtWeight");
var cost = document.getElementById("txtCost");

cost.disabled = false;
weight.disabled = false;
description.disabled = false;

So, how do I remedy the situation to be able to enable any row that is selected. Thanks.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and most people will just move on. Please read this for more information.

Also be sure to enable the 'disable smilies' checkbox so that your code looks less surprised

Lastly, I'm not sure of the practicality of showing code primarily composed of JSP markup in an HTML forum. Perhaps posting the resulting HTML would make more sense.

You can go back and change your post to add code tags by clicking the .

[Asking smart questions] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

It looks to me as if you are assigning the same id values to the element of each row of the table. An id value needs to be unique within a page.

You'll need to assign unique ids to each page element.
I agree. Here's the link:
subject: disabling and enabling input fields in a table
jQuery in Action, 3rd edition