I create a model form using ct-js-productForm library but now i want to open that model using on click event. Right now when i refresh the page bydefault the model is open.I want to open that model using on click event.
<a href="#" id="register"><i class="fa fa-plus-square"></i> Register</a>
<div class="ct-popupForm ct-js-productForm" id ="Registration">
<div class="container">
<form role="form" class="center-block" method="POST">
<div class="form-group">
<div class="ct-form-content">
<div class="row">
<div class="col-md-6">
<label>First Name</label>
<input type="text" required class="form-control input-lg" value="Kristine" placeholder="">
<label>Last Name</label>
<input type="text" required class="form-control input-lg" value="Black" placeholder="">
<label>Number of Properties</label>
<input type="text" required class="form-control input-lg" value="15" placeholder="">
<label>Include contact form?</label>
</div>
</div>
<button type="submit" class="btn btn-success center-block">Save changes</button>
</div>
<div class="ct-form-close"><i class="fa fa-times"></i></div>
</div>
</form>
</div>
</div>
<script>
$(function(){
var options = {
"backdrop" : "static",
"show":true
}
$("#register").on("click", function(){
console.log('hi');
$('#Registration').modal(options);
});
});
</script>
Add modal class to the #Registration div
$(function() { var options = { "backdrop" : "static", "show": true } $("#register").on("click", function() { console.log('hi'); $('#Registration').modal(options); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <a href="#" id="register"><i class="fa fa-plus-square"></i> Register</a> <div class="ct-popupForm ct-js-productForm modal fade" id="Registration"> <div class="container"> <form role="form" class="center-block" method="POST"> <div class="form-group"> <div class="ct-form-content"> <div class="row"> <div class="col-md-6"> <label>First Name</label> <input type="text" required class="form-control input-lg" value="Kristine" placeholder=""> <label>Last Name</label> <input type="text" required class="form-control input-lg" value="Black" placeholder=""> <label>Number of Properties</label> <input type="text" required class="form-control input-lg" value="15" placeholder=""> <label>Include contact form?</label> </div> </div> <button type="submit" class="btn btn-success center-block">Save changes</button> </div> <div class="ct-form-close"><i class="fa fa-times"></i></div> </div> </form> </div> </div>
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <a href="#" id="register"><i class="fa fa-plus-square"></i> Register</a> <div class="modal fade" id ="Registration"> <div class="container"> <form role="form" class="center-block" method="POST"> <div class="form-group"> <div class="ct-form-content"> <div class="row"> <div class="col-md-6"> <label>First Name</label> <input type="text" required class="form-control input-lg" value="Kristine" placeholder=""> <label>Last Name</label> <input type="text" required class="form-control input-lg" value="Black" placeholder=""> <label>Number of Properties</label> <input type="text" required class="form-control input-lg" value="15" placeholder=""> <label>Include contact form?</label> </div> </div> <button type="submit" class="btn btn-success center-block">Save changes</button> </div> <div class="ct-form-close"><i class="fa fa-times"></i></div> </div> </form> </div> </div> <script> $('document').ready(function() { var options = { "backdrop" : "static", "show":true } $("#register").on("click", function(){ $('#Registration').modal(options); }); }); </script> </body> </html>
You forgot to put ; at the end of this.
var options = {
"backdrop" : "static",
"show":true
};
second add class "modal fade" in #Registration div block or set display:none to your #Registration div
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.