Enable and disable php button

Asked

Viewed 431 times

0

I have this edit button which is always available for editing:

<a type="button" name="edit3" id="'.$row["Id"].','.$row["IdConsulta"].'" data-toggle="modal" href="#add_data_Modal3" class="btn btn-primary edit_data3">Editar</a>

I wanted it to be active only at the moment a new record is made in the database table and at midnight of that same day again to be deactivated, and at the moment it is active only allow to edit the new record inserted, in the old records which can be consulted still appear unobtrusive or hidden.

2 answers

1

There are many questions in a single question, so let’s separate them into parts ("Divide and Conquer"):

As for the question of activating the button, you can do it as follows:

//para desabilitar o botão
$('.edit_data3').prop("disabled",true);

//para habilitar o botão
$('.edit_data3').prop("disabled",false);

As for the other issues, they can be solved in various ways (that I will do generically):

function minhafuncao(){
  var dataHora = Date.now();
  var meiaNoite = 23:59;

  if(novoRegistro && dataHora < meiaNoite){
    $('.edit_data3').prop("disabled", false);
  } else {
    $('.edit_data3').prop("disabled", true);
  }
}

now just keep calling this function over and over again.

  • put the script with the function inside the head and call it on the button as follows onclick="minhafuncao()" but I get this mistake Uncaught ReferenceError: novoRegistro is not defined

  • may only explain to what novoRegistro?

  • the newRegister variable would be a boolean that would be returned from some function that checks if any new record has been added.

  • ok, I have to see how to create this function to do this check. I never created

  • can help create this function to check if the new registration has been added? I am not getting it

  • function to check if there has been new registration, can be the function that is in Ajax Success?

  • I have not yet been able to solve this problem that I posed in this question, it may help me to apply its solution?

Show 2 more comments

0


I created a variable with the current date that compares with the date of registration. I created an empty disabled variable. I put this disabled variable in the link. If the date is different from the current date, fill the disabled variable

<?php
$dataAtual = DATE('Y-m-d');
$disabled = "";

if(DATE($row['Data2'])!=$dataAtual){
$disabled = "disabled";
?>

<a type="button" name="edit3" id="'.$row["Id"].','.$row["IdConsulta"].'" data-toggle="modal" href="#add_data_Modal3" class="btn btn-primary edit_data3" '.$disabled.'>Editar</a>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.