Like locking <tr> after clicking once

Asked

Viewed 502 times

2

I have several table row and when click on one <tr> run this script:

 $(function(){
            $('tr').click(function(){
            $("tr").prop("disabled", true);
            var id = $(this).attr('id');
            $.post("shopweb_item.php",{id: id}, function(data){
              $('#resultado').html(data);
              $("#comprar").prop("disabled", false);
            });
          });
        });

Only that even I use:

$("tr").prop("disabled", true);

If the user click more than once the request and repeated then the return of the shopweb_item.php is a modal and ends up opening more than once is after I close still the page darker and impossible to click, someone has any idea?

I took the $("tr").prop("disabled", true); of that other script:

  // evento de "submit"
        $("#comprar").click(function (event) {
            // parar o envio para que possamos faze-lo manualmente.
            event.preventDefault();
            // capture o formulário
            var form = $('#formulario')[0];
            // crie um FormData {Object}
            var data = new FormData(form);
            // caso queira adicionar um campo extra ao FormData
            // data.append("customfield", "Este é um campo extra para teste");
            // desabilitar o botão de "submit" para evitar multiplos envios até receber uma resposta
            $("#comprar").prop("disabled", true);
            // processar
            $.ajax({
                type: "POST",
                enctype: 'multipart/form-data',
                url: "enviar.php",
                data: data,
                processData: false, // impedir que o jQuery tranforma a "data" em querystring
                contentType: false, // desabilitar o cabeçalho "Content-Type"
                cache: false, // desabilitar o "cache"
                timeout: 600000, // definir um tempo limite (opcional)
                // manipular o sucesso da requisição
                success: function (data) {
                    console.log(data);
                    $("#msg").html(data);
                    // reativar o botão de "submit"
                    //limpar form
                      $('#formulario').each (function(){
                          this.reset();
                        });
                    $("#comprar").prop("disabled", false);
                },
                // manipular erros da requisição
                error: function (e) {
                    console.log(e);
                    // reativar o botão de "submit"
                    $("#comprar").prop("disabled", false);
                }
            });
        });

But I take the data of a <from> I don’t know how to get the id of the <tr> with this second script.

HTML:

<tr id="<?php echo $shopweb->id_shop; ?> ">
 <td><img src="<?php echo "$shopweb->icone"; ?>"></td>
 <td><?php echo "$shopweb->nome"; ?></td>
 <td><?php echo "$shopweb->categoria_s"; ?></td>
 <td><?php echo "$shopweb->tipo_s"; ?></td>
 <td><?php echo "$shopweb->level"; ?></td>
 <td><?php echo "$shopweb->preco"; ?></td>
</tr>

1 answer

4


The estate disabled has no effect on tr.

What you can do is disable the event click when you click on tr.

For example:

$("tr").click(function(event) {
    alert("Clicado!");
    $(this).off("click");
});

See working here.

  • It didn’t work the same way.

  • @Everton Figueiredo Changed the line $("tr"). prop("disabled", true)? Which version of your jquery? Can you place the piece of html that is clicked?

  • Yes I will edit.

  • @Evertonfigueiredo Where is the element with the id #buy?

  • 1

    This in a modal that opens, your answer helped a lot so I got.

Browser other questions tagged

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