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

112
Views
Complete el botón del formulario con los parámetros URL + GET sin enviar el formulario

Como no estoy muy familiarizado con JavaScript, necesito un poco de ayuda.

Tengo un formulario simple con 1 línea de título, 1 botón de búsqueda, 1 campo de descripción y el botón de enviar.

 <form action="test_form.php" method="get" id="test_form1"> Überschrift: <input name="label" id="label" type="text" /> <input name="google" type="button" value="google" /><br /> Beschreibung: <textarea id="description" name="description" rows="5" cols="33">Beschreibung eingeben</textarea><br /> </form> <button type="submit" form="test_form1" value="Submit">Eintragen</button>

Si ingreso algo en la línea de encabezado y hago clic en el botón de Google, la página de Google debería abrirse en una nueva pestaña y el texto de la línea de encabezado debería agregarse automáticamente al enlace como parámetro de búsqueda.

Por ejemplo, en la línea de título "imágenes animadas" se abre una nueva pestaña con la URL "https://www.google.com/search?q=animated+Images" al hacer clic en el botón de Google.

Si no aparece en el título, cuando haga clic en Google, la página de Google debería abrirse en una nueva pestaña ("https://www.google.com").

Todo debería suceder sin enviar el formulario real.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Lo que puede hacer es llamar a la función de búsqueda () cuando alguien haga clic en el botón de búsqueda y puede usar la función window.open () para abrir una nueva pestaña con parámetros de consulta

 <script> function search(){ let string = document.getElementById("label").value; window.open("https://www.google.com/search?q="+string); } </script> <input type= <button onclick="search()">Search</button>
about 4 years ago · Juan Pablo Isaza Report

0

Cambié su formulario y tampoco necesita usar el método GET para lo que necesita hacer. Simplemente use el método POST para el formulario para aumentar la seguridad y estas búsquedas en Google se pueden realizar por separado. En primer lugar, debe agregar jQuery para su archivo. Aquí usaré el archivo jquery-2.1.1.min.js.

Código HTML

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <form action="" method="POST" id="serachForm"> Überschrift: <input type="text" id="searchText"> <input type="button" value="Google" id="buttonA"> <br><br> Beschreibung: <textarea id="description" name="description" rows="5" cols="33">Beschreibung eingeben</textarea><br /> <br><br> <input type="submit" value="Submit"> </form> <script src="jquery-2.1.1.min.js"></script> <script src="new.js"></script> </body> </html>

código jQuery

 $(document).ready(function(){ $("#buttonA").click(function(){ let keyWord = $("#searchText").val(); if(keyWord) { window.open("https://www.google.com/search?q="+keyWord); }else{ alert("Input field is empty, Please enter a keyword to search!"); } }); });

Cuando haga clic en el botón de Google, verá que la función de búsqueda está funcionando en una nueva pestaña y el formulario no se envía. Si desea enviar el formulario, puede escribir un código separado en el formulario utilizando jQuery y PHP.

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!