2

I have TextBox and a Button

first the button is in disabled position When the user starts typing the text in textbox the button should be enabled

How can i achieve this using JQuery or Java Script

6 Answers 6

5

Seems like you are a newbie to jQuery. I would say you start with jQuery Tutorials and then move on to jQuery Validate. If you prefer books to start with, you can pick up a copy of jQuery in Action.

Sign up to request clarification or add additional context in comments.

Comments

1

you can try with this also

 <input type='text' id='textbox'>
    <input type="button" class="button-disabled" id="change" disabled="disabled" value="click">


    $("#textbox").keyup(checkForm).focus(checkForm);
    function checkForm()
    {
        if($("#textbox").val()=='')
           {
          $("#change").addClass("button-disabled").removeClass("button");
          $("#change").attr("disabled","disabled");
           }
           else
            {
           $("#change").removeClass("button-disabled").addClass("button");
           $("#change").removeAttr("disabled");
            }
       }

Comments

1
<input type='text' id='textbox'>
<input type="button" id="button'" value="click me"> 

$('#button').attr('disabled', 'disabled');

$('#textbox').change(function(){$('#button').removeAttr('disabled')} );

Comments

1
<input type="text" id="myText">
<input type="submit" id="myButton" disabled="disable"/>


jQuery(function(){

jQuery('#myText').bind('keypress',function(e){
    if((jQuery(e.target).val()+"").length>0)
    {
       jQuery('#myButton').removeAttr('disabled');
    }
    else
    {
       jQuery('#myButton').attr('disabled','disable');
    }
});

});

3 Comments

The if((jQuery(e.target).val()+"").length>0) could be simplified to if( this.value.length > 0 ) considering this will run on every keypress on the text input
I HAVE TO DO WITH ASP COTROLS
use clientID of control or add css class to the control and replace this "jQuery('#myText')" with "jQuery('.your_css_class_name')"
0
<input type='text' id='thetext' value=''>
<input type='button' disabled='disabled' id='thebutton' value='the button'>

$(document).ready(function(){
   $('#thetext').change(function(){
      $('#thebutton').removeAttr('disabled');
   });
});

Read up on the jQuery API : http://api.jquery.com/

1 Comment

I WANT TO DO WITH ASP CONTROLS
0

HTML:

<input type='text' id='textbox'>
<input type="button" id="mybutton" value="click me">

JS:

$(document).load(function() {
    $('#mybutton').attr('disabled', 'disabled');
}

$('#textbox').change(function() {
    $('#mybutton').removeAttr('disabled');
}

Update: regarding the use of jQuery w/ ASP.NET, keep in mind that ASP.NET outputs standard HTML once the page is rendered, so the above code would work similarly, except you need to figure out the ID's of the textboxes generated by ASP.net. See this link for further explanation on this:
http://www.search-this.com/2009/08/06/using-jquery-with-asp-net-controls/

2 Comments

I think this works for HTML controls,but i have asp.net controls
I updated my post to elaborate on the use of jquery w/ asp.net. hope that helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.