Freakyuser
Freakyuser

Reputation: 2814

Enable a button on textarea value change

I have a textarea in my form. Now I want to enable a button once there is a change in the text of the textarea.

I tried using onchange event on the textarea, but, while using it, the browser wants me to click outside the textarea to enable the button, even though I changed some text in the textarea.

My requirement is to enable the button, the moment I change the text.

I have written this function onclick of the textarea:

function enableUpdateButton() {

    document.getElementById("button").disabled = false;

}

What change should I do?

Upvotes: 1

Views: 1757

Answers (3)

Russell Gutierrez
Russell Gutierrez

Reputation: 1385

Use onkeypress, onkeyup or onkeydown attribute on your textarea instead of onchange. The onchange attribute is invoked when focus was changed from textarea to another element.

Upvotes: 2

Robin
Robin

Reputation: 3850

I use keyListeners for this requirements like this:

this.jt_Auftragsnummer.addKeyListener(new KeyAdapter() {

     @Override
     public void keyReleased(KeyEvent arg0) {
     // Do some stuff
     }
}

This works quite nice for me.

Upvotes: 0

Man Programmer
Man Programmer

Reputation: 5356

function enableUpdateButton() {

    document.getElementById("button").disabled = false;

} 
document.getElementById('textareaId').onkeypress=enableUpdateButton();

Upvotes: 2

Related Questions