473,327 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Close suggestion box when user click "Clear" button

How can I close the suggestion box when the user click the Clear button?

When the suggestion box is closed, how can the Search & Clear button move up to its original place?

What code should I insert to do this?

This is my current code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>
  4.             Brandon's Search Engine
  5.         </title>
  6.         <style type="text/css">
  7.             #suggestion {
  8.                 border: 1px solid black;
  9.                 visibility: hidden;
  10.                 position: relative;
  11.                 background-color: white;
  12.                 z-index: 10;
  13.             }
  14.             #suggestion a {
  15.                 font-size: 12pt;
  16.                 color: black;
  17.                 text-decoration: none;
  18.                 display: block;
  19.                 width: 648px;
  20.                 height: auto;
  21.                 text-align: left;
  22.                 padding: 2px;
  23.             }
  24.             #suggestion a:hover {
  25.                 background-color: #dddddd;
  26.                 width: 644px;
  27.                 padding: 2px;
  28.             }
  29.         </style>
  30.         <script type="text/javascript">
  31.  
  32.             //document.getElementById("suggestion")
  33.  
  34.             function getSuggestion(q) {
  35.                 var ajax;
  36.                 if(window.XMLHttpRequest)//for ie7+, FF, Chrome
  37.                     ajax = new XMLHttpRequest();//ajax object
  38.                 else
  39.                     ajax = new ActiveXObject("Microsoft.XMLHTTP");//for ie6 and previous
  40.                 ajax.onreadystatechange = function() {
  41.                     if(ajax.status === 200 && ajax.readyState === 4) {
  42.                         //if result are not there then don't display them
  43.                         if(ajax.responseText === "")
  44.                             document.getElementById("suggestion").style.visibility = "hidden";
  45.                         else {
  46.                             document.getElementById("suggestion").style.visibility = "visible";
  47.                             document.getElementById("suggestion").innerHTML = ajax.responseText;
  48.                         }
  49.                     }
  50.                 };
  51.                 ajax.open("GET", "suggestion.php?q=" + q, false);
  52.                 ajax.send();
  53.             }
  54.         </script>
  55.         <script>
  56.             function validateForm()
  57.             {
  58.             var x=document.forms["q"]["q"].value;
  59.             if (x==null || x=="")
  60.                 {
  61.                 return false;
  62.                 }
  63.             }
  64.         </script>
  65.     </head>
  66.     <body>
  67.         <form method="GET" action="search.php" name="q" onsubmit="return validateForm()">
  68.             <table align="center">
  69.                 <tr>
  70.                     <td>
  71.                         <h1><center>Brandon's Search Engine</center></h1>
  72.                     </td>
  73.                 </tr>
  74.                 <tr>
  75.                     <td align="center">
  76.                         <input type="text" name="q" style="height: 27px; width: 650px; padding: 2px"
  77.                                onkeyup="getSuggestion(this.value)" autocomplete="off" onblur="blur() document.getElementById('suggestion').style.visibility = 'hidden'"/>
  78.  
  79.                         <div id="suggestion" style="width: 648px">
  80.                         </div>
  81.                     </td>
  82.                 </tr>
  83.                 <tr>
  84.                     <td align="center">
  85.                         <input type="submit" name="submit" value="Search" style="height: auto; width: 60px; padding: 2px" />
  86.                         <input type="reset" value="Clear" style="height: auto; width: 50px; padding: 2px" />
  87.                     </td>
  88.                 </tr>
  89.                 <tr>
  90.                     <td align="center">
  91.                         To insert your site in result fill in the form at <a href="insert.php">here</a>.
  92.                     </td>
  93.                 </tr>
  94.             </table>
  95.             <input type="hidden" name="page" value="0" />
  96.         </form>
  97.     </body>
  98. </html>
  99.  
Thanks
Dec 20 '13 #1
0 1204

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Asit | last post by:
How can i know when user clicks X button of the browser ? I have to write some code when user clicks X button of browser. What is the event for capturing this event ? Help needed ASAP. Asit
4
by: feng | last post by:
Hi, In our asp.net app, we need to capture the event when user close the browser window by clicking on the "x" button. But it doesn't seem to be as easy as it sound. Can someone show me how to...
2
by: Steph. | last post by:
Hi, A simple question : How can I detect if the CTRL key is pressed when User click on a control ? Thanks, Steph.
3
by: pawanez4u | last post by:
Hi I am using XAMPP software for PHP programming. As we know that the MS Sql Database which comes with XAMPP is totally GUI based we can create a table and enter the values directly, and also we...
1
by: Chandrajit | last post by:
Hi, Please help I what show some message when user click on X button of form which is at upper side corner of the form in vb.net
3
by: ghjk | last post by:
I have a web page which is used to enter user data. In there I have 4 buttons named as "Submit, Confirm,Edit,Cancel". User should enter data and click "Submit " button. Then I want to display all...
1
by: fsalido | last post by:
How can i point to record in GridView when i click the button to search for lastname? Im using OLEDB AND VISUAL BASIC 2008. thanks!
0
by: mars92 | last post by:
Hi all, I am doing an project for school in IT and I have a GUI that works but I want to add a seperate pane that will become visible and invisible when I click a button. In detail, I am making...
1
by: Karan Singh Goyal | last post by:
I have an access table which have fields like Customer Id, First Name, Last Name etc. i know how to generate auto number but when i delete last record it generates next number instead of previous one...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.