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
2010-10-27 07:11:12
-, no valid xhtml
Andreas Niedermair
2010-10-27 07:13:48
its early, extra {'s tend to sneak in ;)
Sam
2010-10-27 07:16:25
no... i'm takling about the `disabled`-attribute, not about the syntax-error...
Andreas Niedermair
2010-10-27 07:18:26
ah, ok. *goes to fetch cup of coffee* ;)
Sam
2010-10-27 07:25:30
^^ ... there (http://www.w3schools.com/xhtml/xhtml_syntax.asp) you go
Andreas Niedermair
2010-10-27 07:30:30
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
2010-10-27 07:12:41
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
2010-10-27 07:18:55