I'm starting to work with bootstrap. I grabbed some sample code, but it seams not working. And actually I have three questions.
A). Call the first modal is OK. But from this modal, I cannot open the second one.
B). Still from the first modal, I have a button to go back to the contact div in the HTML source, which is not working.
C). From the button JS, calling the function 'Alert_Hello' is OK: it displays the alert, it goes to the internal link #contact but right after the HTML page seems to reload going to the top of the page. Why?
HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<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>
<script type="text/javascript" src="js/modal.js"></script>
<a href="#contact" class="btn btn-primary">Contact</a>
<a href="#about" class="btn btn-primary">About</a>
<!-- Button trigger modal -->
<button class="btn btn-success" data-toggle="modal" data-target="#MdlSignIn">Sign In</button>
<a href="" class="btn btn-danger" onclick="Alert_Hello()">JS</a>
<!-- Modal -->
<div class="modal fade" id="MdlSignIn" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4>Sign In Input</h4>
</div>
<div class="modal-body">
<form role="form" action='#' method="post">
<input type="text" class="form-control" placeholder="Username">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" id="signin">Sign In</button>
<button type="button" class="btn btn-primary" id="signin-cnt">Contact</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="MdlSignInErr" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Sign In Error</h4>
</div>
<div class="modal-body">
<p>Please review your sign in input.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<div id="contact">Contact us</div>
<a href="#top" class="btn btn-primary">Top</a>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<div id="about">About us</div>
<a href="#top" class="btn btn-primary">Top</a>
</body>
</html>
JavaScript code called from the HTML:
//set button id on click to hide first modal
$("#signin").on( "click", function() {
$('#MdlSignIn').modal('hide');
$('#MdlSignInErr').modal('show');
});
$("#signin-cnt").on( "click", function() {
$('#MdlSignIn').modal('hide');
window.location="#contact";
});
function Alert_Hello() {
alert('Hello from external JavaScript!');
window.location="#contact";
}
I'm using bootstrap 3.3.7 for both css and js and I'm using jquery 3.2.1.
Thank you in advance for your tips.