kevin
kevin

Reputation: 234

how to open a modal after 3 sec?

code:

<script>
   $(document).ready(function()
     {
       setInterval(function() 
         {
           $('#contact').modal();
         }, 3000);
     });
</script>

html code:

<a href="#contact"><h4><i class="fa fa-phone"></i>Contact Us</h4></a>
<div id="contact" class="modalDialog">
<div> 
  <a href="#close" title="Close" class="close">X</a>
    <h2>Thanks For Visiting Us</h2>
    <form method="post">
      <input type="text" name="name" id="name" placeholder="Enter Your Name">
      <input type="text" name="email" id="email" placeholder="Enter Your Email">
      <input type="text" name="phone" id="phone" placeholder="Enter Your Phone">
      <input type="text" name="message" id="message" placeholder="Enter Your Message">
      <input name="captcha_code" type="text" value="" placeholder="Enter the code">
      <img src="captcha.php" id="capImage"/>
      <br/>Can't read the image? click here to  <a href="javascript:void(0);" onclick="javascript:$('#capImage').attr('src','captcha.php');">refresh</a>.
      <input type="submit" name="insert" id="insert" value="Submit" placeholder="Enter Your Message" >
  </form>
</div>

I want when page is load after 3 sec modal will open. Here, I m using setinterval method for open modal after 3 sec but it can't. So, How can I open modal after 3 second using setinterval method ?

Thank You

Upvotes: 0

Views: 121

Answers (2)

Imperial Softech
Imperial Softech

Reputation: 26

First thing be sure that you have included bootstrap.min.js

Change in this html

    id="contact" class="modalDialog"    

to

    id="contact" class="modal"    

When you use .modal() function, the main class of that model should be "modal". Your script function is working fine, just change the class.

Upvotes: 1

Suresh Suthar
Suresh Suthar

Reputation: 812

use setTimeout function

$(window).on('load', function($) {
    setTimeout(function(){
   $('#contact').modal();
 }, 3000);
  })

Upvotes: 0

Related Questions