Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda