Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
¿Cómo redirigir al usuario a un nuevo sitio web después de enviar el <formulario>?

Estoy tratando de redirigir al usuario a una nueva página web dependiendo de su entrada de formulario usando JavaScript si el usuario escribe something en el formulario, así que quiero que lo lleven a website.com/something y si escribe else , entonces quiero lo llevará a website.com/else , así que básicamente quiero almacenar la entrada de '#inputbox' cuando hace clic en Intro o en el botón de búsqueda y luego quiero redirigir al usuario a un sitio web usando let website = 'website.com/' + input luego redirigirlos a website.com/input

 <form action="#" type="submit" id="form"> <input type="text" name="search" id="inputbox"> <input type="submit" value="Go To" id="button"> </form>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Pude hacerlo funcionar usando este código:

 document.addEventListener ('input', function() { let form = document.getElementById("form"); let text = document.getElementById("inputbox").value; let response = 'website.com/' + text; form.onsubmit = function() { window.location = response; return false; }; });
about 4 years ago · Juan Pablo Isaza Report

0

En su archivo JavaScript ( app.js en el ejemplo a continuación), enlace a su botón y al cuadro de entrada:

 const linkButton = document.querySelector('#button'); // link to button const inputBox = document.querySelector('#inputbox'); // link to inputbox linkButton.addEventListener('click', evt => { const routeUrl = inputBox.value; // value from the input box let baseUrl = evt.target.getAttribute('href'); // get href fom btn href attrib baseUrl = baseUrl.slice(-1) === '/' ? baseUrl : baseUrl + '/'; // add a trailing slash window.open(baseUrl + routeUrl, target='_blank'); // target='_self' opens the link in the same tab });

Y, en su HTML :

 <form action="#" type="submit" id="form"> <input type="text" name="search" id="inputbox"> <input type="button" value="Go To" id="button" href="https://your.com/"> </form>

Y enlace a JavaScript justo antes de la etiqueta del cuerpo de cierre:

 <script src="app.js"></script>

Esto debería funcionar, si esa es la ruta que elige tomar.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!