richrock Posted April 17, 2009 Share Posted April 17, 2009 Hi all Having a little difficulty with a function I got from the net. It's kind of working, but there's one thing bugging me. The search box displays the result of a mysql search based on what you type. Not a problem. Here's the code: <ul style='list-style-type:none; list-style-image:none; background-image:none;'><?php while ($row = mysql_fetch_array($getRecord)) { $namesearch = ""; $surname = strtolower($row['surname']).", "; $namesearch .= ucfirst($surname); if ($row['firstname'] != NULL) { $fname = strtolower($row['firstname']); $namesearch .= ucfirst($fname." "); } if ($row['secondname'] != NULL) { $sname = strtolower($row['secondname']); $namesearch .= ucfirst($sname." "); } if ($row['thirdname'] != NULL) { $tname = strtolower($row['thirdname']); $namesearch .= ucfirst($tname." "); } if ($row['fourthname'] != NULL) { $foname = strtolower($row['fourthname']); $namesearch .= ucfirst($foname." "); } if ($row['fifthname'] != NULL) { $finame = strtolower($row['fifthname']); $namesearch = ucfirst($finame); } ?> <li style="list-style-type:none; list-style-image:none; background-image:none;"><a href="#" onclick="document.getElementById('search-q').value='<?php echo $namesearch; ?>';"> <?php echo $namesearch; ?> </a></li> <?php } ?></ul> As you can see, the text box is filled with the selected using the onclick. But... the list still remains. How can I get this list to dissappear once the user has clicked on a link? EDIT - Sorry, the title was poorly worded. I need to clear the auto-suggest box once a selection has been made. I can get the auto-suggest fine TIA Link to comment https://forums.phpfreaks.com/topic/154505-onclick-needs-to-clear-auto-suggest-options/ Share on other sites More sharing options...
mtoynbee Posted April 17, 2009 Share Posted April 17, 2009 Encapsulate the UL with a div such as: <div id="listDiv"></div> Then amend your onclick section onclick="document.getElementById('search-q').value='<?php echo $namesearch; ?>'; document.getElementById('listDiv').style.display='none';" Link to comment https://forums.phpfreaks.com/topic/154505-onclick-needs-to-clear-auto-suggest-options/#findComment-812380 Share on other sites More sharing options...
richrock Posted April 17, 2009 Author Share Posted April 17, 2009 Superb! Really must knuckle down and learn some JS.. I've got a week off soon, maybe then I'll... Anyway, thanks a lot! Got me out of a scrape there! Link to comment https://forums.phpfreaks.com/topic/154505-onclick-needs-to-clear-auto-suggest-options/#findComment-812403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.