i am trying to achieve live seacrh. when i enter any text in the text field it should match with the text in available in options. then it should show the matching options under textbox. So far i have tried this. What i have achieved is i have got the matching text, and i am alerting it. But i want it to drop down list with matching results.
Code
<select name="location_to" class="full-width">
<?php
foreach ( $flight_locations as $flight_location ) {
echo '<option value="' . esc_attr( $flight_location->term_id ) . '" ' . ' >' . esc_html( $flight_location->name ) . '</option>';
}
?>
</select>
**jquery code**
$('#location_from_input').keyup(function(){
var txt = $(this).val().toLowerCase();
// window.alert(txt);
// lenght = this.value.length;
$('#location_from>option').each(function () {
var text = $(this).text();
textL = text.toLowerCase();
// window.alert(txt);
(textL.indexOf(txt) == 0) ? window.alert(text) : $(this).hide();
});
})
I need your help. Thanks I Advance.