Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
Returning selected table/cell value back to parent window fails when using variable

I'm trying to return the value of a clicked-row from a table in a popup window back to the parent window.

It works correctly if I manually specifiy a value in the script.

window.opener.document.getElementById('adminticket').value = 12345; // this works fine

If I extract the value from the table that was clicked on and output the value that shows the correct value.

console.log (selectedticket); // this works fine

However, if I put the variable to be returned it does nothing and no console errors.

Full code:

<script>
    jQuery(document).ready(function($) {
        $(".clickable-row").click(function() {
            
            var table = document.getElementsByTagName("table")[0];
            var tbody = table.getElementsByTagName("tbody")[0];
            tbody.onclick = function (e) {
                e = e || window.event;
                var selectedticket = 0;
                var target = e.srcElement || e.target;
                while (target && target.nodeName !== "TR") {
                    target = target.parentNode;
                }
                if (target) {
                    var cells = target.getElementsByTagName("td");
                    selectedticket = (cells[0].innerHTML);
                }
            };                                
            
            console.log (selectedticket); // this works fine
            window.opener.document.getElementById('adminticket').value = 12345; // this works fine
            window.opener.document.getElementById('adminticket').value = document.getElementById(selectedticket); // this doesnt work
            window.opener.document.getElementById('adminticket').value = selectedticket; // this doesnt work
            
            this.window.close();
        });
    });
</script>

What am I missing here? Any ideas?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda