pmark019
pmark019

Reputation: 1209

How to enable a disabled JSP button in Java?

I want to have something like this:

public void setButton(){
     document.getElementById('scan').disabled=false; 
}

scan is the ID of the button in the JSP.

Upvotes: 0

Views: 16450

Answers (3)

Santosh
Santosh

Reputation: 17923

What you are dealing here is html and javascript and not java. Java based systems at the server will generate the html/css/js based code (after executing the JSP) and send it to browser. For enable/disabling and disabling the buttons, use javascript.

Not sure what you use case is, but you can use following javascript code code to enable/disable the buttons

document.getElementById("scan").disabled = true;

This can be called on any event (like page load etc)..

EDIT: In light of new requirement (Capture USB events), this may not be as straightforward as it seemed. I would suggest following approach.

  1. Write a signed Java Applet. This Applet will use some USB interfacing APIs (e.g jUSB) to listen to the USB plugin events.
  2. Then, from this Applet use Applet Javascript interaction to call the javascript function to enable the button (assuming that the button is disabled when the page loaded).

So it works as follows

  • When you hit the URL, browser loads the page and Applet (with Scan button disabled by default)
  • You plugin the USB device
  • Java code in the applet listens to this event
  • The listener calls the Javascript function in the page which enables the Scan button.

Upvotes: 1

Qilin Lou
Qilin Lou

Reputation: 406

maybe you can use this

document.getElementById("scan").disabled = true;

or jquery

$("#scan").disable = true;

Upvotes: 0

Suresh Atta
Suresh Atta

Reputation: 122008

All the HTML in JSP compiles on server side and comes to Client.

If you want to do something you need to make a request.

You can do it directly with html in your jsp

<input type="button" name=myButton   id="scan"  value="disable" disabled>

If javascript

document.getElementById("scan").disabled=true;  //not false

Upvotes: 0

Related Questions