skip to Main Content
<a href="oaccept1.php?id=<?php echo $data['oaid'];?>" class="btn btn-sm btn-primary login-submit-cs" 
onclick="return confirm('Are You Sure')">ACCEPT</a>

this is the button 'm talkin' about

want to disable that button after accepting that and it should stay disabled after accepting that doc

2

Answers


  1. I suggest you make it a button, otherwise a simple visit from a google bot will accept all

    Alternative is to use a form submit event

    window.addEventListener("DOMContentLoaded", () => {
      const sub = document.querySelector(".login-submit-cs");
      const dis = false; //  localStorage.getItem("submitted"); // remove "false; //" to activate
      if (!dis) sub.removeAttribute("disabled");
      sub.addEventListener("click", (e) => {
        let  tgt = e.target.closest("button"); // using closest in case the element has children
        if (!tgt || dis) return; // not the link
        setTimeout(() => tgt.setAttribute("disabled","disabled"),200); // allow the button to be pressed
        // localStorage.setItem("submitted",true); // remove comment lines to activate
        location = tgt.dataset.href;
      });
    });
    <button data-href="oaccept1.php?id=<?php echo $data['oaid'];?>" class="btn btn-sm btn-primary login-submit-cs" disabled>ACCEPT</button>
    Login or Signup to reply.
  2. Use server side, don’t depend on only javascript

    In table add new field as accepted and make it false by default,

    ALTER TABLE `tbl_name` ADD `accepted` BOOLEAN default false;
    

    on click of accept button event function, set this field as true

    INSERT INTO `table_name`(id, accepted) VALUES ('2',true );
    

    Then in your php have

    <?php  if($data['accepted']==false){?>
      <a href="oaccept1.php?id=<?php echo $data['oaid'];?>" class="btn btn-sm btn-
         primary login-submit-cs" 
         onclick="return confirm('Are You Sure')">
         ACCEPT
      </a>
    
    <?php }else {?>
    
     <a  class="btn btn-sm btn-
         primary login-submit-cs" 
         disabled>
         ACCEPT
      </a>
    <?php }?>
    

    hope this will help you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search