Link to home
Start Free TrialLog in
Avatar of Moses Dwana
Moses Dwana

asked on

HOW TO INSERT INTO MYSQL DATABASE WITHOUT PAGE REFRESH

on my form i have two buttons ( confirm and print buttons) i set the print button to hide and want to display it when the confirm button is click while at the same updating my table to say that this record have been confirm. now, what is happening when i click the confirm button, the table is updated but the print button show up for a second and then set back to hidden. i want the print button to show up permanently.  thanks for your help!!!
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Using JQuery functions and sessionStorage property see the following simply example.Actually I set a session variable after click on submit button and then after the refresh of the page an if condition check if exist the print variable to set the display inline or not.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<title>HTML5, CSS3 and JavaScript demo</title>
  <style>
   .print{
     display: none;
    }
  </style>
</head>
<body>
<!-- Start your code here -->

  <form action="" method="post">
     <input type="text" />
    <button type="submit" class="submit">Submit</button>
    <button type="button" class="print">Print</button>
  </form>
  <script>
    $(window).load(function(){
  if(sessionStorage.getItem('print')){   
    $('.print').css('display','inline');
    sessionStorage.removeItem('print');    
  }
  
  $('.submit').on('click',function(){
    if(!sessionStorage.getItem('print')){
      sessionStorage.setItem('print',true);
     
    }
  });
}); 
     
  </script>
<!-- End your code here -->
</body>
</html>

Open in new window

Avatar of Moses Dwana
Moses Dwana

ASKER

thanks in advance, let me try this and see
thank you so mush it worked!!!!!
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks very mush, things are working fine. i actually forgot to close the question.