1

I have a form on my website. When the submit button is activated I would like a bootstrap modal to appear and stay until you press the button on the modal to get back to the main menu. The modal appears for a second and then disappears. When I press the 'back' button on my browser window the modal then appears and stays until I press the 'ok' button on the modal. Any suggestions to a solution?

<html lang="en">

<head>
    <meta charset="utf-8">    
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/bootstrap_cerulean.min.css" rel="stylesheet">
    <style type="text/css">
    body {padding-top:20px;}    </style>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js">           </script>
</head>

<body>
<div class="container">
<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <div class="well well-sm">
      <form class="form-horizontal" action="" method="post">
       <fieldset>
        <legend class="text-center">Udlevering af rute</legend>

        <!-- Bud input-->
        <div class="form-group">
          <label class="col-md-3 control-label" for="Bruger">Avisbud</label>
          <div class="col-md-9">
            <input id="Bruger" name="Bruger" type="text" placeholder="Skriv bud navn" class="form-control">
          </div>
        </div>

        <!-- Avisrute nr.-->
        <div class="form-group">
          <label class="col-md-3 control-label" for="Rute nr">Rute nr.</label>
          <div class="col-md-9">
            <input id="Rute nr" name="Rute nr" type="text" placeholder="Skriv rute nr." class="form-control">
          </div>
        </div>

        <!-- Form actions -->
        <div class="form-group">
          <div class="col-md-12 text-center">
            <button type="submit" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#udlevering_Modal">Udlevér rute</button>
          </div>
        </div>
      </fieldset>
      </form>
    </div>
  </div>
</div>
</div><script type="text/javascript">
</script>
</body>
</html>


<html lang="en">

<head>
<meta charset="utf-8">    
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap_cerulean.min.css" rel="stylesheet">
<style type="text/css">
    body {padding-top:20px;}    </style>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js">       </script>
</head>

<body>
<div class="modal fade" id="udlevering_Modal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
      <div class="row">
      <div class="col-md-6 col-md-offset-3">
      <div class="well well-sm">
         <div class="alert alert-success" role="alert">Rute udleveret.</div><br />
        <a class="btn btn-lg btn-primary btn-large" href="manuel_opret.php" role="button"><span class="glyphicon glyphicon-briefcase"></span>  Til manuel menu &raquo;</a> 
        </div>
     </div>
  </div>
</div><script type="text/javascript">
</script>
</body>
</html>
Thomas
  • 15
  • 1
  • 6
  • 2
    Maybe this one could help you (seems to be solved) - [Bootstrap Modal immediately disappearing](http://stackoverflow.com/questions/13648979/bootstrap-modal-immediately-disappearing?rq=1) – Ramiz Wachtler Sep 06 '14 at 19:52
  • Possible duplicate of [Bootstrap Modal immediately disappearing](https://stackoverflow.com/questions/13648979/bootstrap-modal-immediately-disappearing) – merv Dec 29 '17 at 18:10
  • @RamizWachtler is correct. This code clearly double loads the Bootstrap JS (head, then body), which is addressed in the linked post. – merv Dec 29 '17 at 18:14

2 Answers2

4

I was also facing the same issue couple of days back but dis trick worked for me, just change the button type to anchor tag as shown below. e.g

<a type="submit" class="btn btn-primary" data-toggle="modal" href="#myModal">Submit</a>  

according to me the reason of the issue might be that it is trying to submit the form that's why the modal disappears immediately Hope dis would help you..

Bhargav
  • 51
  • 4
0

Couple of issues. You have multiple HTML and body tags. You only need the modal div with your first HTML/Body tags.

Second you don't want the modal as a submit button on a form. Try type=button instead.

chconger
  • 107
  • 4