views:

29

answers:

4

hi, i m a beginner. i want that when a checkbox is checked then it should allow user to write something in a txtbox. initially the txtbox is disabled. what i should write inside the function using jquery

A: 
$('#mycheckbox').click(function() 
{ 
   $("#mytextbox").attr('disabled','');
}
);
Sam
-, no valid xhtml
Andreas Niedermair
its early, extra {'s tend to sneak in ;)
Sam
no... i'm takling about the `disabled`-attribute, not about the syntax-error...
Andreas Niedermair
ah, ok. *goes to fetch cup of coffee* ;)
Sam
^^ ... there (http://www.w3schools.com/xhtml/xhtml_syntax.asp) you go
Andreas Niedermair
A: 
<input type="checkbox" id="cb" />
<label for="cb">label for checkbox</label>
<input type="text" id="txt" disabled="disabled" />

<script type="text/javascript">
    $(document).ready(function() {
        var checkbox = $('#cb');
        var textfield = $('#txt');

        checkbox.click(function() {
            if (checkbox.is(':checked')) {
                textfield.removeAttr('disabled');
            }
            else {
                textfield.attr('disabled', 'disabled');
            }
        });
    });
</script>

working example with visibilty
working example with disabled-state

additionally: as you are working with asp.net, your assignments should look like, eg:

var checkbox = $('#<%= this.cb.ClientID %>');

you should be aware of the way how the server-controls get rendered either (to choose an appropriate selector).
furthermore: you should also be aware of the fact, that disabled-inputs won't get posted, whereas readonly-inputs are no problem to handle...

Andreas Niedermair
A: 

http://drupal.org/node/116548

prick
A: 
$(document).ready(function() 
{
    //To Disable the Check box on page Load
    $('#TextBox').attr('disabled', 'disabled');     

    //On Click of the Check Box 
    $('#CheckBoz').click(function() 
    {
        if($('#CheckBoz').is(':checked'))
        {
            $('#TextBox').removeAttr('disabled');            
        }
        else
        {           
            $('#TextBox').attr('disabled', 'disabled');            
        }    
    });
});

I Hope this code works perfectly for you and u jst need to paste it in your page and check the Component name according to it.

Nitesh Katare