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.