Skip to content
Advertisement

Keep button disabled till the current page reloads (using Jquery)

I have a search bar in index.php and when I type an ID, the SQL data is fetched from fetch.php. The fetch.php contains “AddToZip” button for each row of SQL data. When I click on a selected button, the selected button is disabled (going properly till here). But when I clear the search bar to write a different ID or perhaps same ID, all the disabled buttons of “AddToZip” are reactivated/enabled. How do I keep them disabled when the user uses the search bar multiple times and they anyhow get enabled only when the user refreshes the page.

index.php

JavaScript

fetch.php

JavaScript

Advertisement

Answer

Can you add the code of AddToZip.php ?

You could store all ids into a session value, and check if the id is containt inside this array on your fetch.php.

AddToZip.php :

JavaScript

fetch.php :

JavaScript

And to clear the stored values, you have two solutions :

  1. Keep other session datas

    session_start();
    if (isset($_SESSION[‘added_to_zip_ids’]))
    unset($_SESSION[‘added_to_zip_ids’]);

  2. Clear everything

    session_start();
    session_unset();

These line can be anywhere on the server.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement