Skip to content
Advertisement

Disabling/Enabling a button through button click

I am displaying SQL data in rows and each row contains “Add To Zip” Button. The button for each row is enabled. I want to disable the current row’s button on click. I later want to re-enable these disabled buttons through another button in a different php file. How do I achieve this? Also, please do not point to SQL injection, I have used login details to check if the correct credentials are added or not and I will be only posting the code that I think is relevant to this question.

FetchData.php

JavaScript

AddToZip.php

JavaScript

EDIT: I am using AJAX to display the fetched values from FetchData.php

Index.php

JavaScript

Advertisement

Answer

There are a couple of issues with your HTML markup. I.e. you have a <button> tag inside an anchor <a> tag which is technically incorrect. However, you most likely have some Bootstrap styling on the button tag and are only using the anchor to action the AddToZip.php call right?

If that’s the case, I would rather strip out the <a> tag and use an onclick method on the <button>. An example:

Replace

JavaScript

With

JavaScript

To be clear

This is not an ideal solution, just a quick fix to achieve what the OP asked for help with. To the OP, I highly recommend using an Ajax call of sorts to communicate to the back-end.

I suggest looking into jQuery’s AJAX API


Update after OP updated Question

So now that I see you are using jQuery AJAX calls, add a function to your script section:

JavaScript

Then change your markup to this (remove the iframe as well):

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