Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys, Nowadays am working on php site and in this site, i have a textbox and I want to make this text box auto1suggest.
guys please see my code and suggest me how can i do it.
Thanks.

What I have tried:

// keywords
				if( empty($fields) || in_array('keywords', $fields) ){
					$ret .= '<div class="tourmaster-tour-search-field tourmaster-tour-search-field-location" >';
					$ret .= '<label>' . esc_html__('Enter Your_Location', 'tourmaster') . '</label>';
					$ret .= '<div class="tourmaster-tour-search-field-inner" >';
					$ret .= '<input name="tour-search" type="text" value="' . (empty($_GET['tour-search'])? '': esc_attr($_GET['tour-search'])) . '" />';
					$ret .= '</div>';
					$ret .= '</div>';
				}else{
					$ret .= '<input name="tour-search" type="hidden" value="" />';
				}
Posted
Updated 22-Aug-17 1:22am

1 solution

Aside from not knowing exactly what you want to suggest.

Recall: php is server-side,so you need something else on the client side to pick up what the user has typed. (onblur() onkeyup(), onchange() . . . )

With that in mind, you have basically two options, depending in part on how large a list of suggestions you have to work with.

If it's short, you can download the list and use javascript to keep an eye on your textbox content and make suggestions according to whatever rule you use. If it's a long list, you'll probably have it on the server - and that would require the javaScript to use AJAX to check the server and return suggestions.

Then, by either route, you need to determine how and where on the page to display them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900