aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Enable/Disable a text box based on checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Enable/Disable a text box based on checkbox" Watch "Enable/Disable a text box based on checkbox" New topic
Author

Enable/Disable a text box based on checkbox

Nagendra Shastry
Greenhorn

Joined: Oct 26, 2010
Posts: 19

Hi All,

I have a table of data. Few columns in each row has to be read only when loaded and when the check box in corresponding row is checked,these fields has to be enabled for editing.

My code for column is <display:column property="panelSerialNumber" style="text-align:right" titleKey="rmalcd.label.serial" sortable="false"></display:column>

Can someone help me in doing this? I can't use jquery(It is restriction from manager)

Regards,
Shyam
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1527
Is it JQuery or Javascript that is restricted by manager?


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Nagendra Shastry
Greenhorn

Joined: Oct 26, 2010
Posts: 19

He told me not to use jquery. We can use javascript. Here we have a table of data. Once we check the checkbox that row has to be enabled for editing. we should be able to edit multiple rows before clicking on Update All button to update multiple rows.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

Firstly, this isn;t a JSP question so it's been moved to the HTML forum.

Secondly, your manager is ill-informed. Most people use jQuery to make their in-browser script easier and more robust.

Make the text inputs initially disabled. Establish a change handler on the table. When a checkbox changes to checked, find the text inputs in the same row and remove the disabled attribute.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I am being nice today while updating my laptop.

HTML



JavaScript



Running Example

http://jsfiddle.net/HG73V/
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
And without testing, I think the jQuery code is simply:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

With jQuery (roughly off the top of my head -- may need debugging):


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

Dueling posts: Eric snuck in in front of me!

In any case, it's clear from both examples that it's a lot less code to do it with jQuery (and multiple ways to do it).

What possible reason could there be for "Don't use a library that will make you more productive and produce more robust cross-browser code"?
Nagendra Shastry
Greenhorn

Joined: Oct 26, 2010
Posts: 19
Hey thanks a lot Bear and Eric.. Resolved the issue with your support...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enable/Disable a text box based on checkbox