Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, everyone

I am not getting the result for below code. Here chkWarranty is the checkbox id and strOriginalRA is the textbox id. Before that textbox is disabled only. But when I am clicking on checkbox it should beenabled. For that I have used below code but I am not getting result.

Can anbody please help to find this answer ??

JavaScript
$(function () {
        disabletextbox();
    });
    function disabletextbox(chkWarranty, strOriginalRA) {
        if (document.getElementById("chkWarranty").checked == true) {
            document.getElementById("strOriginalRA").disabled = false;
        }
        else {
            document.getElementById("strOriginalRA").disabled = true;
        }
    }
Posted
Updated 15-Jul-13 22:04pm
v4
Comments
Johnny J. 16-Jul-13 4:06am    
I have given you question a descriptive subject line instead of just "help me" - That way you're more likely to get the right people to help you!

try this

$(document).ready(function(){$('#<%=chkWarranty.ClientID%>').click(function () {
            $('#<%=strOriginalRA.ClientID%>').attr("disabled", !$(this).is(":checked"));
             if ($(this).is(":checked")) {
   $('#<%=strOriginalRA.ClientID%>').attr('style', 'color:black;background-color:white;width:90px;');
}
else {
                $('#<%=strOriginalRA.ClientID%>').attr('style', 'color:black;background-color:#c0c0c0;width:90px;');
              }
});});
 
Share this answer
 
Comments
Apali 16-Jul-13 3:59am    
its not working..
Zafar A khan 16-Jul-13 4:14am    
i have already implemented this working 100% . copied from my project. have you included the jquery file... this is jquery bro
Apali 16-Jul-13 4:21am    
but when i am using in ASP.NET MVC that time totally error its showing...how to solve..
[no name] 16-Jul-13 4:47am    
post the error what u get in browser error console(ctrl+shift+J).
So that we will help u better!!
I think u have not included the javascript library file.
Zafar A khan 16-Jul-13 4:52am    
#<%=strOriginalRA.ClientID%> this will give an error
Check the ID of textbox and checkbox using firebug
just past that ID of textbox and checkbox here

Like this $('#ctl00_ContentPlaceHolder1_TabContainer1_tabSchoolInfo_FrmSchoolInfoView_strOriginalRA')
try this....:)

C#
<script type="text/javascript" language="javascript">
    function enableTextBox() {
        var textBoxID = "<%= strOriginalRA.ClientID %>";
        if (document.getElementById("<%= chkWarranty.ClientID %>").checked == true)
            document.getElementById(textBoxID).disabled = false;
        else
            document.getElementById(textBoxID).disabled = true;
    }
</script>
and than the control:
<asp:checkbox checked="false" onchange="javascript:enableTextBox();" id="chkWarranty" runat="server" xmlns:asp="#unknown" />
<asp:textbox id="strOriginalRA" enabled="false" text="Test" runat="server" xmlns:asp="#unknown" />
 
Share this answer
 
C#
<script type="text/javascript">
function checktxtbox() 
{
  if (document.getElementById("chkWarranty").checked == true) 
    {
         document.getElementById("strOriginalRA").disabled = false;
    }
  else 
    {
       document.getElementById("strOriginalRA").disabled = true;
    }
}
</script>

Another approach based on comment by OP:
XML
<script type='text/javascript'>
        $('#chkWarranty').click(function(){
            if($(this).attr('checked') == true){
                 $('#strOriginalRA').attr("disabled","disabled");
            } else {
                $('#strOriginalRA').removeAttr('disabled');
            }
        });
</script>


Call it like:
C#
<input type="checkbox" id="chkWarranty"  onclick="checktxtbox()"></input>

Regards.. :laugh:
 
Share this answer
 
v5
Comments
Apali 16-Jul-13 3:51am    
I checked this code also it is not working...any other method if you know please help..
Thanks7872 16-Jul-13 3:59am    
refer to updated answer.
Apali 16-Jul-13 4:07am    
this update one also not working i tried...have you tried this code??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900