0

I have a javascript function that is triggered when a button is pressed. That function loads an external page with the values of a field.

My problem is that when I refresh the page my clicked button is reset. What I want is to keep that button value when it refreshes so it still loads that page and only reset when another button is pressed.

js code

<script>
    $(function() {
        $("button.btn").click(function() {
            var tip = document.getElementById("tip5").value;
            var id_local = document.getElementById("id_local").value;
            $("#tipuri_rezervare").load("select_tip_rezervare.php?id=" + id_local + "&tip=" + tip);
        });
    });
</script>

php code

$stmt = $dbh->prepare("SELECT * 
                FROM Tip_Rezervare  
                INNER JOIN Local ON Local.ID_Local=:id_local
                INNER JOIN Leg_Tip_Local ON Tip_Rezervare.ID_Tip=Leg_Tip_Local.ID_Tip and Leg_Tip_Local.ID_Local=:id_local");
$stmt->bindParam(':id_local', $id, PDO::PARAM_INT);
$stmt->execute() ;
while ($row = $stmt->fetch()) {
    $local = $row['Denumire_Local'];
    echo'<button type="button" class="btn btn-danger" id="tip'.$row['ID_Tip'].'" value="'.$row['ID_Tip'].'">'.$row['Nume'].'</button>';
}   
?>
</div>

<form id="tip" method="post">
    <input type="hidden" name="id_local" id="id_local" value="<?php echo $id;?>">
    <div id="tipuri_rezervare"></div>
3
  • 1
    With a session maybe?
    – Daan
    May 21, 2014 at 12:14
  • 4
    You will have to use some sort of storage - session variable, cookie, database - to store the value of the button and then retrieve that value on refresh. May 21, 2014 at 12:15
  • solved with creating a session of tip on select_tip_rezervare.php and verifing it on refresh. thnx May 21, 2014 at 13:05

1 Answer 1

0

You need to make an Ajax call & set a session during the result fetch from external page but before page refresh and read the session values after page refreshed & set it on page.

2
  • Please do not post comments ans answers. May 21, 2014 at 12:57
  • you can read the session value during the page is refreshed using php and set that value for button pressed
    – Dipak
    May 22, 2014 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.