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

123
Visualizações
Fetch or clone data from input field

I am currently having some issues with the following script:

    <input name="MYNEWVALUE" class="MYNEWVALUE" maxlength="20" type="text" id="MYNEWVALUE">
    <a onclick="addURL(this)" href="<?php echo $escaped_url?>">Click this</a>
    
    <script>
    function addURL(element)
    {
        $(element).attr('href', function() {
            return this.href + '?notes=...';
        });
    }
    </script>

As you can see I have an input field which I called MYNEWVALUE and a Button with a Javascript function. This button once clicked adds a specific parameter to my URL e.g. https://myurl.com/?notes=...

What I am currently trying to achieve is to fetch the data from the input field (as soon as the Button has been clicked) and use it or clone it directly in conjunction to this.href + '?notes=MYNEWVALUE';

So If I would enter Testing the final URL to be passed on should become https://myurl.com/?notes=Testing

Is there a way to intercept or clone this value? Some expert help would be greatly appreciated, thank you.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you can do is change how you're handling the event handling and simplify it like so:

<a href="<?php echo $escaped_url?>" id="button">Click this</a>

<script>
    $("#button").on("click", function() {
        this.href += "?notes=" + $("#MYNEWVALUE").val();
    });
</script>

jQuery .click() documentation as follows (note you cannot use an ES6 function for this one due to the ES6 arrow function's lexical this).

about 4 years ago · Juan Pablo Isaza Relatório
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