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

116
Visualizações
how to make a getElementById value available for another page

I have a form that has two input fileds, I want the value entered in the first page to be available when redirected to another route?

I have an '/instances' route which renders an 'instances' view, this 'instances' view has two input text which ids are 'Instances' and 'Region' and a button id = 'runScriptButton' that has onclick = "launchTerraform()"

once the button is clicked it executes the launchTerraform() and redirects the user to the '/dashboard' route, in this route there is a button as well with id = 'destroyButton'. in this '/dashboard' route, I would like to have access to the input values entered by the user in the '/instances' page.

Here is what I have tried so far, but It does not work, once on '/dashboard', 'data' is not accessible.

function launchTerraform() {
  // this is the data I would like to be able access from /dashboard route
  var data = {
    instances: document.getElementById('Instances').value,
    region: document.getElementById('Region').value
  }
   
  if (document.getElementById('runScriptButton') ){

    var xhr = new window.XMLHttpRequest()
    xhr.onreadystatechange = function () {
    if (this.readyState === 4 && this.status === 200 ) {
      window.location.href = '/dashboard'
    }
  }
  document.getElementById("test").textContent = "Please wait ...";
  xhr.open('POST', '/provision', true)
  xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
  xhr.send(JSON.stringify(data))
}

   if (document.getElementById('destroyButton')){
    var xhr = new window.XMLHttpRequest()
    xhr.onreadystatechange = function () {
    if (this.readyState === 4 && this.status === 200 ) {
      document.getElementById("divDestoyResources").textContent = "Resources Deleted"
    }
  }
  document.getElementById("divDestoyResources").textContent = "Please wait while resources are released ...";
  xhr.open('POST', '/destroy', true)
  xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
  xhr.send(JSON.stringify(storeData))
}
   
}
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