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

121
Views
¿Es posible que un texto de entrada de formulario tenga dos salidas de acción?

Lo que me gustaría hacer es poder escribir algo en el campo de entrada de texto del formulario y presionar uno de los botones para buscar los resultados que yo elija: Google, Bing, DuckDuckGo o cualquier otro que desee agregar.

Tengo esto:

 <form method="get" action="https://www.google.com/search?="> <input type="reset" /> <input type="text" name="q" autocomplete="off" autofocus /> <input type="submit" value="Google Search"/> <input type="submit" value="Bing Search"/> </form>

Vi una publicación aquí, pero desafortunadamente, el código no estaba completo:¿Es posible tener dos acciones en un formulario?

Esa publicación mostró

 <form id="search" action="" method="get" onsubmit="javascript: return SubmitForm();"> <.... ret of the form> </form>

y js

 function SubmitForm() { showResultDiv(); document.forms['search'].action='http://www.google.com/search'; document.forms['search'].target='frame_result1'; document.forms['search'].submit(); document.forms['search'].action='http://www.bing.com/search'; document.forms['search'].target='frame_result2'; document.forms['search'].submit(); return false; }

Por lo que parece, es posible pero no estoy seguro de cómo. Cualquier idea sin PHP. ¿Solo HTML y JS? Gracias por tu tiempo.

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

0

Podrías hacerlo usando HTML solamente.

HTML

 <form method="get" target="blank" > <input type="reset" /> <input type="text" name="q" autocomplete="off" autofocus /> <input type="submit" value="Google Search" formaction="https://www.google.com/search"/> <input type="submit" value="Bing Search" formaction="https://www.bing.com/search"/> </form>

Encontré esto aquí

about 4 years ago · Juan Pablo Isaza Report

0

Tal vez esta no sea la mejor solución, pero funciona y es más seguro que el método get. si se llama win2 antes de ganar, se centrará en la ventana de Google.

 <form id="form" role="search"> <input type="search" id="query" name="q" placeholder="Search..." aria-label="Search through site content"> <button>Search</button>
 const f = document.getElementById('form'); const q = document.getElementById('query'); const google = 'https://www.google.com/search?q=+'; const bing = 'https://www.bing.com/search?q=+' const site = ''; function submitted(event) { event.preventDefault(); const urlG = google + site + '+' + q.value; const urlB = bing + site + '+' + q.value; const win = window.open(urlG, '_blank'); const win2 = window.open(urlB, '_blank'); win.focus(); win2.focus(); } f.addEventListener('submit', submitted);
about 4 years ago · Juan Pablo Isaza Report

0

Esto funciona:

HTML:

 <form method="get" target="blank" > <input type="reset" /> <input id="the-text" type="text" name="q" autocomplete="off" autofocus /> <button id="submit">Search</button> </form>

JavaScript:

 let search = document.getElementById('submit') search.addEventListener("click", searchFunction); function searchFunction() { let searchText = document.getElementById('the-text').value; window.open('https://www.google.com/search?q='+searchText) window.open('https://www.bing.com/search?q='+searchText) }

Desafortunadamente, los navegadores generalmente bloquean la apertura de 2 o más pestañas al mismo tiempo. Por lo tanto, puede permitir las ventanas emergentes y buscará tanto en Google como en Bing. Si las ventanas emergentes están bloqueadas, solo mostrará el resultado de búsqueda de Google y bloqueará Bing.

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!