Jump to content

onclick needs to clear auto suggest options


richrock

Recommended Posts

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

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';"

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.