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

168
Vistas
Using a Datalist to intelligently redirect

I've been searching this site and others for what I believe may be a unique solution to a particular problem.

In essence, I have a search function on my website. It consists of a form which takes user input and compares it to movie dialogue stored within a MySQL table via my results.php page.

However, I'd like the search function to perform a dual purpose. Using a Datalist, I'd like the search function to display a list of available titles (generated dynamically using PHP which I am more than confident enough to do) and if a user selects one of them and presses enter, they will be directed automatically to the corresponding title page (i.e. display.php?urn=0001).

If, however, the user enters a string which is not within the Datalist, it will redirect them to results.php for the standard search results.

This is what I've come up with so far:

<html>
<body>
<form method='POST' action='results.php'>
 <input name="search" type="text" id="txtAutoComplete" list="TitleList"
    onkeydown = "if (event.keyCode == 13)
                    window.location='display.php?urn=' + this.value"
    placeholder="Search dialogue" />

<datalist id="TitleList">
        <option value="0001">After Life</option>
        <option value="0002">Blazing Saddles</option>
        <option value="0003">Million Ways to Die in the West, A</option>
        <option value="0004">Inbetweeners, The</option>
</datalist>
</form>
</body>
</html>

The other issue is that when a user selects a title from the Datalist options, the title changes to its value. For example, when you select "After Life", the input displayed in the search field changes to 0001 which is a little confusing for my visitors.

Is there a way of preserving the title but re-directing to the value (in this case display.php?urn=0001) AND is there a way of re-directing to results.php IF the entered value isn't contained within the Datalist?

Sorry if I've made this more confusing than it needs to be but I struggled to describe what I want to achieve here!

Any help anyone could give me would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
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