Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Enable/disable button when enter/delete text in a textbox using Javascript

Enable/disable button when enter/delete text in a textbox using Javascript

Scheduled Pinned Locked Moved ASP.NET
javascriptdebugginghelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chakran
    wrote on last edited by
    #1

    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

    V 1 Reply Last reply
    0
    • C chakran

      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

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • V Vasudevan Deepak Kumar

        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

        C Offline
        C Offline
        chakran
        wrote on last edited by
        #3

        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,

        W 1 Reply Last reply
        0
        • C chakran

          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,

          W Offline
          W Offline
          www Developerof NET
          wrote on last edited by
          #4

          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.

          C 1 Reply Last reply
          0
          • W www Developerof NET

            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.

            C Offline
            C Offline
            chakran
            wrote on last edited by
            #5

            Hi, onkeyUp is working perfectly. thanks for your reply.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups