Home > ASP.Net, Javascript > Disaple Button until CheckBox has been checked

Disaple Button until CheckBox has been checked


Hi

try these example :

Example 1:

<script language="javascript">
function validate(){
var cb = document.getElementById('CheckBox1');
if (cb.checked)
{
 return true;
}
else
{
 alert('CheckBox was not checked!');
 return false;
}
}
</script>

<asp:Button ID="Button1" Text="Agree" runat="server" OnClientClick="javascript:validate();">

 
Example 2:
Step 1 : Place a CheckBox an button on page

<asp:CheckBox ID="CheckBox1" runat="server" Text="Agree" />
<asp:Button ID="Button1" runat="server" Text="Button"  Enabled="false" />

step 2: add following javascript to the page:

 <script type="text/javascript">
    function SetStatus()
    {
      
        if(document.getElementById('<%=CheckBox1.ClientID%>').checked)
        {
            document.getElementById('<%=Button1.ClientID%>').disabled = false;
        }
        else
        {
            document.getElementById('<%=Button1.ClientID%>').disabled = true;
        }
        return false;
    }
    </script>

Step 3: Add Attribute the CheckBox

CheckBox1.Attributes.Add("onchange", "SetStatus();");

Good Luck

Advertisements
Categories: ASP.Net, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: