Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I have an asp.net button which is disabled by default. I have a textbox with multiline mode. If textbox is empty then button should remainn disabled and if there is text in it, then button will be enabled. Below is my javascript code.
<script>
    function SetButtonStatus(sender, target) {
        debugger
        var first = document.getElementById('<%=txtMain.ClientID %>');
 
        
        if (sender.value.length >= 1 && first.value.length >= 1)

            document.getElementById(target).disabled = false;

        else
            document.getElementById(target).disabled = true;

    }
</script>

This is my textbox.
<asp:TextBox runat="server" ID="txtMain"  Rows="200" TextMode="MultiLine"
            Columns="150"  onkeyup="SetButtonStatus(this, 'btnsubmit')"></asp:TextBox><br />


Now, if I chose TextMode="MultiLine". my javascript function doesnt woprk. It works perfect if I remove multiline mode. I tried using textarea instead of textbox yet it didnt work. I also try having html button instead of asp.net button, yet it is not working.

Any help would be appreciated. Thanks.
Posted
Updated 6-Jan-14 22:25pm
v2
Comments
Karthik_Mahalingam 7-Jan-14 4:30am    
the above code works fine..
JL_Coder 7-Jan-14 4:48am    
Thanks for your effort. I realized that it wasn't the problem with the code, but with the text editor plugin I used with the textarea. It doesn't work when I have plugin.
Please check my answer Solution 2. :)
Karthik_Mahalingam 7-Jan-14 4:51am    
welcome JL_Coder :)

Change your code to... There is no need to check first.value.length >= 1 as keyup Event is fired from that TextBox only.

It is working, tested at my end.
JavaScript
function SetButtonStatus(sender, target) {
    if (sender.value.length >= 1)
        document.getElementById(target).disabled = false;
    else
        document.getElementById(target).disabled = true;
}
 
Share this answer
 
The code works fine !!
JavaScript

 
Share this answer
 
Comments
JL_Coder 7-Jan-14 4:47am    
Thanks for your effort. I realized that it wasn't the problem with the code, but with the text editor plugin I used with the textarea. It doesn't work when I have plugin.

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