Search code examples
javascriptbuttonclicking

Disable button by clicking button


So I was trying to disable a certain button on the entire page and every page onwards by clicking the same button. Meaning the user can only use it once. Now it just doesn't seem to work out :/ I've tried to create a variable and make this variable occur on every single page with $SESSION, and if the variable does not equal to '' it would disable the button, but it doesn't work.. The button is on page A and needs to be disabled on page A when the user reloads the page/submits a form. My code:

My session start:

<?php      
session_start(); 
      $hulplijn = $_SESSION['hulplijn'];
      $_SESSION['hulplijn'] = $hulplijn;
?>

My button that disables the button once it is clicked:

<script>
      function get_accept(input)
        {
            alert(input);
        }
        function changeText(el)
        {
            el.innerHTML = 'Al gebruikt!';
        }
      </script>

<button onclick="changeText(this); get_accept('<?php echo $hulplijn;?>'); this.disabled='disabled';">Hulplijn</button>

Anyone that can help me out here? Would be much appreciated!


Solution

  • So the thing I wanted to do isn't possible, too bad.. Instead I was better of just allowing users to use the button more than once.