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

153
Vistas
Appending current URL parameters onto anchor link

At a page like

https://www.example.com/?firstname=Steven&lastname=Smith&email=steve%40gmail.com&phone=0404555555

I have a button (anchor link) #ptsBlock_553944 .ptsCell:nth-of-type(1) .ptsEditArea.ptsInputShell that links to https://www.example.com/form

I'd like to append the URL parameters from the current URL to the button's URL, so that the button's href is now https://www.example.com/form/?firstname=Steven&lastname=Doig&email=steve%40gmail.com&phone=0404555555

How can I do this with JavaScript please?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Use window.location.search:

var url = "https://exmaple.com";
var newurl = url + window.location.search;

newurl will contain all the get (ex. ?something=something&something2=something5) data.

To change the href of a:

var button = document.getElementById('#ptsBlock_553944');
button.href = button.href + window.location.search;
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you don't care about supporting older browsers you can use the URL API and URLSearchParams.

function appendCurrentUrlSearchParams(anchorElement) {
  const currUrlSearchParams = new URL(window.location.href).searchParams;
  const link = new URL(anchorElement.href);

  // uncomment this line if you want to clear query parameters already present in the anchor url
  // link.search = '';

  for (const entry of currUrlSearchParams.entries()) {
    link.searchParams.append(entry[ 0 ], entry[ 1 ]);
  }
  
  anchorElement.href = link.href;
}

Usage in your case:

appendCurrentUrlSearchParams(document.querySelector('#ptsBlock_553944 .ptsCell:nth-of-type(1) .ptsEditArea.ptsInputShell'));
about 4 years ago · Juan Pablo Isaza Denunciar

0

Read Html select using select to change the link of a button with Javascript

specifically the section on

  1. Get the element with something like document.getElement MDN getElement Link

  2. Change the .href of that element to what you want.

function selectFunction() {
    var x = document.getElementById("selectopt").value;

    document.getElementById("mylink").innerHTML = x;
  
    document.getElementById("mylink").href = "http://www." + x + ".com";
  
}
document.location.pathname = '/questions/69240453/appending- 
current-url-parameters-onto-anchor-link/69240510';

//get the document pathname I chose from document.location
let data = document.location.pathname;

let preUrlString = 'www.example.com/form';

let newString = preUrlString + data;

console.log(newString);
'www.example.com/form/questions/69240453/appending- 
current-url-parameters-onto-anchor-link/69240510'

document.getElementById("mylink").href = newString;
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