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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.