Enable/disable button when enter/delete text in a textbox using Javascript
-
Hi, whenever user enter text in a textbox have to disable button and if user removes text from textbox should enable button. How can we implement on client side using javascript.? I tried with onkeypress and onkeydown. but when ever I press key it is not capturing keyvalue. Can anyone help me? pls see the below code. function disablebutton() { debugger; var prefix = 'ctl00_ContentPlaceHolder1_'; var btnRecharge = document.getElementById(prefix +'btnRecharge'); var txtpromo = document.getElementById(prefix +'txtBonusPromo'); if(txtpromo.value =='') { btnRecharge.disabled = false; } else { btnRecharge.disabled= true; } } Thanks
-
Hi, whenever user enter text in a textbox have to disable button and if user removes text from textbox should enable button. How can we implement on client side using javascript.? I tried with onkeypress and onkeydown. but when ever I press key it is not capturing keyvalue. Can anyone help me? pls see the below code. function disablebutton() { debugger; var prefix = 'ctl00_ContentPlaceHolder1_'; var btnRecharge = document.getElementById(prefix +'btnRecharge'); var txtpromo = document.getElementById(prefix +'txtBonusPromo'); if(txtpromo.value =='') { btnRecharge.disabled = false; } else { btnRecharge.disabled= true; } } Thanks
chakran wrote:
'ctl00_ContentPlaceHolder1_
This is a bad practice. Try getting the actual generated Id from the .ClientID property from codebehind.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
chakran wrote:
'ctl00_ContentPlaceHolder1_
This is a bad practice. Try getting the actual generated Id from the .ClientID property from codebehind.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis LevinsonOk. the problem is when ever I press key first time the button is not disabled. If i enter 2nd character this time the button is disabled. the problem is it is not capturing the letter what I pressed at that moment. The same problem occur when am trying to delete using backspace. I deleted all the characters from textbox, then button is not enabled. when I press backspace again eventhough no characters in textbox, this time button is enabling.. main problem is when ever I press key it is not capturing at that moment.. Thanks,
-
Ok. the problem is when ever I press key first time the button is not disabled. If i enter 2nd character this time the button is disabled. the problem is it is not capturing the letter what I pressed at that moment. The same problem occur when am trying to delete using backspace. I deleted all the characters from textbox, then button is not enabled. when I press backspace again eventhough no characters in textbox, this time button is enabling.. main problem is when ever I press key it is not capturing at that moment.. Thanks,
there doesn`t seems prob with ur code...I haven`t tried but try using onkeyup....BTW use clientID instead on generating ID`s on the fly.
When you fail to plan, you are planning to fail.
-
there doesn`t seems prob with ur code...I haven`t tried but try using onkeyup....BTW use clientID instead on generating ID`s on the fly.
When you fail to plan, you are planning to fail.