Chatra
Chatra

Reputation: 3139

Show bootstrap Dialog on Checkbox Check Change

Here is my Jquery Code. I want to show bootstrap confirm Dialog when user check or uncheck the checkbox. How can I do this ?

  $("#chkAdmin").change(function () {     
        if (this.checked) {               
            $("#divAdmin").find("*").prop("disabled", true);
        } else {
            $("#divAdmin").find("*").prop("disabled", false);
        }
    });

I want to show bootrap Yes No modal first and based on Yes or No, I want execute the above code.

Upvotes: 0

Views: 3126

Answers (3)

priya786
priya786

Reputation: 1834

Try this

  $("#chkAdmin").change(function () {     
    if ($(this).prop('checked')) {  
        var answer = confirm("Are you sure?")
        if (answer){
            alert("Yes")
             $("#divAdmin").show();

        }
        else{
            alert("No");
             $("#divAdmin").hide();
        }

    } 
});

Upvotes: 1

Leandro Papasidero
Leandro Papasidero

Reputation: 3738

Try this:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<!-- stylesheets -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

<!-- javascript/jQuery -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.3.0/respond.js"></script>
<![endif]-->

</head>
<body>

<div class="container">
    <form action="http://localhost.testing/modal-processing.php" class="col-sm-6 form-horizontal" role="form" method="GET">
        <label>Landlord<span class="mandatory">*</span></label>

        <!-- modal caller -->
        <input type="checkbox" href="#modal-dialog" class="modal-toggle" data-toggle="modal" data-href="http://localhost.testing/modal-processing.php" data-modal-type="confirm" data-modal-title="Delete Property" data-modal-text="Are you sure you want to delete {$property.address_string}?" data-modal-confirm-url="{$base_url}/id/{$property.id}"><i class="icon-trash"></i> Modal Submit</a>

    </form>
</div>
<div id="modal-dialog" class="modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <a href="#" data-dismiss="modal" aria-hidden="true" class="close">×</a>
                <h3>Are you sure</h3>
            </div>
            <div class="modal-body">
                <p>Do you want to submit the form?</p>
            </div>
            <div class="modal-footer">
                <a href="#" id="btnYes" class="btn confirm">Yes</a>
                <a href="#" data-dismiss="modal" aria-hidden="true" class="btn secondary">No</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>

Upvotes: 0

Ringo
Ringo

Reputation: 3965

Try this:

$("#chkAdmin").change(function () {     
        if ($(this).prop('checked')) {  
            $("#divAdmin").show();
        } else {
            $("#divAdmin").hide();
        }
    });

Upvotes: 0

Related Questions