thenature4u Posted April 1, 2008 Share Posted April 1, 2008 i working with 3 files, i am displaying the code in the 3 files here. iam getting the output also, but the output format is not correct. just iam able to display the names when he writes something in the text box. but the user has to click the names, which are getting from array. how to do this one. thanking u in advance, txthint.html <html> <head> <script src="clienthint.js"></script> </head> <body><form name="f1"> <table> <tr> <td> First Name: </td> <td> <input type="text" id="txt1" onkeyup="addlocdata(str=this.value)"> </td> </tr> <tr> <td> <p>Usernames: <span id="txtHint"></span></p> </td> <td> <div id="dispid"></div> </td> </tr> </form> </body> </html> clienthint.js var req; function loadReq(){ var req = false; req=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP"); return req; } function loadviapost(url, id, parameters,str) { req=loadReq(); if (str==0) { document.getElementById("dispid").innerHTML=""; return; } if(req) { req.onreadystatechange = function(){ if (req.readyState==4){ document.getElementById(id).innerHTML=req.responseText; } } req.open("POST", url, true); //These lines are necessery req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", parameters.length); req.setRequestHeader("Connection", "close"); req.send(parameters); } } function addlocdata(str) { var poststr = "q=" + encodeURI( document.forms.f1.txt1.value ); loadviapost('gethint.php', 'dispid', poststr,str); } gethint.php <?php header("Cache-Control: no-cache, must-revalidate"); // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Fill up array with names $a[]="Anna"; $a[]="Brittany"; $a[]="Cinderella"; $a[]="Diana"; $a[]="Eva"; $a[]="Fiona"; $a[]="Gunda"; $a[]="Hege"; $a[]="Inga"; $a[]="Johanna"; $a[]="Kitty"; $a[]="Linda"; $a[]="Nina"; $a[]="Ophelia"; $a[]="Petunia"; $a[]="Amanda"; $a[]="Raquel"; $a[]="Cindy"; $a[]="Doris"; $a[]="Eve"; $a[]="Evita"; $a[]="Sunniva"; $a[]="Tove"; $a[]="Unni"; $a[]="Violet"; $a[]="Liza"; $a[]="Elizabeth"; $a[]="Ellen"; $a[]="Wenche"; $a[]="Vicky";//get the q parameter from URL $q=$_REQUEST["q"];//lookup all hints from array if length of q>0 if (strlen($q) > 0) { $hint=""; for($i=0; $i<count($a); $i++) { if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))) { if ($hint=="") { $hint=$a[$i]; } else { $hint=$hint." \n ".$a[$i]; } } } } // 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/98936-autocomplete/ Share on other sites More sharing options...
zenag Posted April 1, 2008 Share Posted April 1, 2008 r u expecting this ... if ($hint == "") { $response="no suggestion"; } else { //$response=$hint; echo "<input type='button' name='name' value='$hint'>"; } Link to comment https://forums.phpfreaks.com/topic/98936-autocomplete/#findComment-506231 Share on other sites More sharing options...
thenature4u Posted April 1, 2008 Author Share Posted April 1, 2008 no. dont u know auto complete? the user should be able to access those values(after clicking a particular value the should be displayed in text box). Link to comment https://forums.phpfreaks.com/topic/98936-autocomplete/#findComment-506241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.