Snoken
Snoken

Reputation: 103

HTML/javascript Automatic popup instead of onclick?

So I got this input right now and it works as it should. But I want to create another page with the same popup, but this one should run automaticly instead of onclick. Any tips on how to get it working?

<input type="submit" id="checkin" method="post" action="checkin.php" href = "javascript:void(1)" onclick = "document.getElementById('light1').style.display='block';document.getElementById('fade').style.display='block'" value="Check in">
    <div id="light1" class="white_content">
        <form id="formen" name="myForm" action="checkin.php" method="POST">'
        sAlot of content
        </form>
    </div>

Upvotes: 2

Views: 433

Answers (4)

Naeem Shaikh
Naeem Shaikh

Reputation: 15715

1) write the logic for displaing the popup in script and remove the input tag

  <div id="light1" class="white_content">
        <form id="formen" name="myForm" action="checkin.php" method="POST">'
        sAlot of content
        </form>
  </div>


<script>
    document.getElementById('light1').style.display='block';
    document.getElementById('fade').style.display='block'
</script>

2) Or you can also trigger the click event on input using jquery

<input type="submit" id="checkin" method="post" action="checkin.php" href = "javascript:void(1)" onclick = "document.getElementById('light1').style.display='block';document.getElementById('fade').style.display='block'" value="Check in">
    <div id="light1" class="white_content">
        <form id="formen" name="myForm" action="checkin.php" method="POST">'
        sAlot of content
        </form>
    </div>


 <script> 
      $('#checkin').trigger('click');
 </script>

Upvotes: 2

Roman Bekkiev
Roman Bekkiev

Reputation: 3118

Add your script to onload handler of body tag the same way as to onclick.

<body onload="document.getElementById('light1').style.display='block';document.getElementById('fade').style.display='block'">
  <!-- all your stuff -->

</body>

Upvotes: 0

David Hughes
David Hughes

Reputation: 378

You can include the JS in a script tag before your closing body tag instead of it being an onclick event.

Upvotes: 0

Jamie Barker
Jamie Barker

Reputation: 8246

You can trigger the "click" on the page load: http://api.jquery.com/trigger/

e.g. :

$('#checkin').trigger('click');

Although I can't remember whether or not you will need to put your "onclick" code into a:

$('#checkin').on( 'click', function() {

(I would do it anyway because IMO it's cleaner)

Upvotes: 0

Related Questions