nethken nethken - 4 months ago 21
Javascript Question

How to show alert box after the link is click

Hello this is what i want to do. I want to show the alert box after the user click the link. My link is directed to another php page but it will come back again to the page where the link is found. How can i achieve this? Can someone give me ideas on how to do it?

this is what i tried but not working.

<?php

function fsa() {
echo '<div class="alert alert-success alert-dismissable" id="success-alert">';
echo '<strong>Successfully posted!</strong>';
echo '</div>';
}


<a class='btn btn-info left-margin' href="dbf-import.php" onclick="fsa()">Import Database</a>

Answer

This is an example to show the dissmissable alert box when clicking on a button.

$(document).ready(function() {
  $('.activater').click(function() {
    $('.alert').show()
  })
});
.alert {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />

<body>
  <div class="container">
    <h2>Dismissal Alert Messages</h2>
    <button class="activater">Send Message</button>
    <a class="activater">SHOW MESSAGE</a>
    <div class="alert alert-success alert-dismissable">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
      Success! message sent successfully.
    </div>

  </div>
</body>