0

I have someone done the below aspx file

Right now the button action need manually triggered by pressing "search" button, I want to achieve that button page to be automatically trigger the action itself without needing person to clicked it, how to I accomplish this?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="scripts/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="scripts/CheckBookingApp.min.js"></script>
<script>
    $(document).ready(function () {
        $("#btnSearch").CheckBooking();
    })
</script>
</head>
<body>
<form id="form1" runat="server">
    <div>
        <button id="btnSearch">Search</button>
    </div>
</form>
</body>

2 Answers2

1

Just call your checkBooking() function inside your domready.

You can have it so the popup is displayd when the button is clicked as well.

  $(document).ready(function() {

  function checkBooking() {
    alert('Checking booking');
  }

  // when the page loads
  checkBooking();
    
  //when the button is pressed
  $("#btnSearch").on('click', function() {
    checkBooking();
  });
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form>
  <button id="btnSearch">Check booking</button>
</form>
0

you can trigger a "simulated click" event by javascript $('btnSearch').trigger('click');

if you wish to incorporate a time delay you can use setTimeout()

in your example:

$(document).ready(function () {
    $("#btnSearch").CheckBooking();
    setTimeout(function() { 
           $("#btnSearch").trigger('click');
        }, 5000 /* 5000ms = 5sec */);
});
Tomer W
  • 3,395
  • 2
  • 29
  • 44