0

I am developing MVC application. I have check box and submit button.

I want to enable submit button on check box's checked event and on unchecked submit button should disable.

How to do this ?

I have below code....

    @model PaymentAdviceEntity.Account
    @using PaymentAdviceEntity;


    @{
        ViewBag.Title = "Create";
        PaymentAdvice oPA = new PaymentAdvice();
        oPA = (PaymentAdvice)ViewBag.PaymentAdviceObject;

      <div>
             <input type="checkbox" class="optionChk" value="1" /> Paid
        </div>

    <input type="submit" value="Create"  />
    <input type="button"  class="btn-primary" />
    }

    <script type="text/javascript">
$(".optionChk").on("change", function () {
    if ($(this).is(":checked"))
    {
        alert("1");

        $(".SubmitButton").attr("disabled", "disabled"); 
    } else 
    {
        alert("2");

        $(".SubmitButton").attr("enable", "enable"); 
    }    
});
</script>
Nil
  • 133
  • 2
  • 7
  • 23
  • 1
    Possibly duplicate of http://stackoverflow.com/questions/577548/how-can-i-disable-a-button-in-a-jquery-dialog-from-a-function – rhughes Mar 22 '13 at 13:14

4 Answers4

2

You should be using prop to set/get the disabled property

$(".optionChk").on("change", function () {
     $("input[type=submit]").prop("disabled",!this.checked);   
});

Also your submit button has no class='Submit' so you need to use the attributes selector.. or give it the class='Submit' and use $('.Submit') in place of $('input[type=submit]')

FIDDLE

wirey00
  • 33,517
  • 7
  • 54
  • 65
0

Try this:

$(".optionChk").on("change", function () {
    if ($(this).is(":checked")) {
        $("input[type=submit]").removeAttr("disabled");
    } else {
        $("input[type=submit]").attr("disabled", "disabled");
    }    
});

JSFiddle

Sergio
  • 6,900
  • 5
  • 31
  • 55
0

Try this:

$(function(){
    $('.optionChk').click(function(){
        $('input[type="submit"]').toggle('fast');
    });

});

and the HTML:

<div>
         <input type="checkbox" class="optionChk" value="1" checked="checked" /> Paid
    </div>

<input type="submit" value="Create"  />

working FIDDLE

Karthik Chintala
  • 5,465
  • 5
  • 30
  • 60
0

Disable Submit Button:

$(".optionChk").on("change", function () {

if ($(this).is(":checked")) 
{
$("input[type='submit']").attr('disabled',false); //button will be enabled
}
else
{
$("input[type='submit']").attr('disabled',true); //button will be disabled
}
})

Code to enable or disable submit button :

$("input[type='submit']").attr('disabled',true); //button will be disabled
Hitesh Modha
  • 2,740
  • 5
  • 28
  • 47