xwishmasterx Posted May 2, 2011 Share Posted May 2, 2011 I am looking for some info on creating a textfield /dropdown menu that works just like a standard browser: when you type in something in the textfield/dropdown it should show results (this is needed to quickly find a member) eg. I type "use" and dropdown should contain members(results) starting with "use" (user1, user2 ...) Anyone know where I can find info on this? Link to comment https://forums.phpfreaks.com/topic/235330-need-info-about-textfield-dropdown/ Share on other sites More sharing options...
JKG Posted May 2, 2011 Share Posted May 2, 2011 i know this isnt terribly useful to you now but i have a good one, but on one of my external drives at home (im not at home til tonight (late!)) but if all else fails i can get you the whole script. it was a while ago but i think its js, and not jquery. Link to comment https://forums.phpfreaks.com/topic/235330-need-info-about-textfield-dropdown/#findComment-1209322 Share on other sites More sharing options...
xwishmasterx Posted May 2, 2011 Author Share Posted May 2, 2011 that would be great! I can wait for the right script thanks alot. Link to comment https://forums.phpfreaks.com/topic/235330-need-info-about-textfield-dropdown/#findComment-1209323 Share on other sites More sharing options...
JKG Posted May 2, 2011 Share Posted May 2, 2011 cool lets hope a) i still have it and b) its as good as i thought it was 2 years ago! Link to comment https://forums.phpfreaks.com/topic/235330-need-info-about-textfield-dropdown/#findComment-1209325 Share on other sites More sharing options...
kney Posted May 2, 2011 Share Posted May 2, 2011 I don't know if this code is 100% correct but here goes... The HMTL page: <html> <head> <script type="text/javascript"> function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","gethint.php?q="+str,true); xmlhttp.send(); } </script> </head <body> <p><b>Start typing a name in the input field below:</b></p> <form> First name: <input type="text" onkeyup="showHint(this.value)" size="20" /> </form> <p>Suggestions: <span id="txtHint"></span></p> </body> </html> The PHP page: (I think the while loop needs to be different) <?php $sql = mysql_query("SELECT name from members"); //get the q parameter from URL $q=$_GET["q"]; //lookup all hints from array if length of q>0 if (strlen($q) > 0) { $hint=""; while($result == mysql_fetch_array($sql)) { if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))) { if ($hint=="") { $hint=$result[0]; } else { $hint=$hint." , ".$result[0]; } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint == "") { $response="no suggestion"; } else { $response=$hint; } //output the response echo $response; ?> Link to comment https://forums.phpfreaks.com/topic/235330-need-info-about-textfield-dropdown/#findComment-1209340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.