wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes enabling button when text field changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "enabling button when text field changes" Watch "enabling button when text field changes" New topic
Author

enabling button when text field changes

Lee Sha
Ranch Hand

Joined: Nov 02, 2007
Posts: 66
Hi,
I have a jsp screen in which there are so many text boxes. There is a button at the bottom of the screen. This button will be initially disabled. Once I click on any of the text boxes, the button should be enabled. Can anyone tell me how can I do that without calling a function in the onchange event of every textbox control.
[ December 07, 2007: Message edited by: Bear Bibeault ]

Never tired...
SCJP SCWCD INS21 INS22 INS23 Salesforce Dev401
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
You could do it on the onclick of the body tag, and then you can set focus to the first text box and then enable the button. The only problem is that if they click on a specific text box you will be taking the focus out of the box that was just clicked on.

Why have the button disabled in the first place if the only criteria to enable it is that they click inside of a text box? That's not really any criteria at all.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lee Sha
Ranch Hand

Joined: Nov 02, 2007
Posts: 66
Actually, the user will enter some criteria in one or more of the text boxes and then click on the button which in my case is a "Run Report" button. Once that is clicked, it will be disabled so that the user cannot submit the same report again. The user should be able to submit the report only when he changes the criteria. For that reason, I want to check whether the user clicks on any of the text box even though he does not change the criteria. I am not sure if there is a way to check whether the criteria is changed without adding any complex code.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

Originally posted by Bryce Martin:
You could do it on the onclick of the body tag
Huh? Why would he do that?

The event listeners should be placed on the text field that will do the triggering.
[ December 07, 2007: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

Originally posted by Lee Sha:
I am not sure if there is a way to check whether the criteria is changed without adding any complex code.
Would not an onchange listener be sufficient?
[ December 07, 2007: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

Please also be sure to take the time to compose descriptive subjects for your posts; read this for more information.

I have adjusted the subject of this post for you.
Lee Sha
Ranch Hand

Joined: Nov 02, 2007
Posts: 66
If a report takes long time to come back, the user will hit the same report again thinking it is still not submitted. I want to limit that as it creates unnecessary traffic. There are so many text boxes in the screen. Adding event listener for each text box will have so much impact. Is there any other way I can handle this?
[ December 07, 2007: Message edited by: Lee Sha ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Doing the following just says they clicked on a textbox, it does not give you any info that they actually added data. Plus it does not work if they use tab to fill in the form.



Now you can have JavaScript add the event handlers



I wrote both of them here untested so they maybe buggy.

Eric
Lee Sha
Ranch Hand

Joined: Nov 02, 2007
Posts: 66
I will try that. Thanks for your help.
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
Do you have some sort of time constraints? Just add the listeners. If you do it right you will be much happier with the results and they will be much more controlled.
Lee Sha
Ranch Hand

Joined: Nov 02, 2007
Posts: 66
I am confused where to include the above pieces of code. Could you please guide me through this?
Lee Sha
Ranch Hand

Joined: Nov 02, 2007
Posts: 66
I do not have any time constraints. This is not the only screen that I have to change. There are some 30 screens. Each screen has nearly 30 to 40 controls. That is the reason why I was trying to control it from one function.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Put it inside of script tags and include it on the page inside the head or body tag.

Eric
Lee Sha
Ranch Hand

Joined: Nov 02, 2007
Posts: 66
This code is not called at all. I included it in the body within <script> tags. Please advice.
 
 
subject: enabling button when text field changes
 
Similar Threads
GUI Ideas
dynamic text box
selecting a table row with 3 columns and sending it to another page.
searching
How to Upload files from Browser with single window?