Jump to content

jasoncdenson

New Members
  • Posts

    2
  • Joined

  • Last visited

jasoncdenson's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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? You can see the buttons when you run this code. This is my current code: <html> <head> <title> Brandon's Search Engine </title> <style type="text/css"> #suggestion { border: 1px solid black; visibility: hidden; position: relative; background-color: white; z-index: 10; } #suggestion a { font-size: 12pt; color: black; text-decoration: none; display: block; width: 648px; height: auto; text-align: left; padding: 2px; } #suggestion a:hover { background-color: #dddddd; width: 644px; padding: 2px; } </style> <script type="text/javascript"> //document.getElementById("suggestion") function getSuggestion(q) { var ajax; if(window.XMLHttpRequest)//for ie7+, FF, Chrome ajax = new XMLHttpRequest();//ajax object else ajax = new ActiveXObject("Microsoft.XMLHTTP");//for ie6 and previous ajax.onreadystatechange = function() { if(ajax.status === 200 && ajax.readyState === 4) { //if result are not there then don't display them if(ajax.responseText === "") document.getElementById("suggestion").style.visibility = "hidden"; else { document.getElementById("suggestion").style.visibility = "visible"; document.getElementById("suggestion").innerHTML = ajax.responseText; } } }; ajax.open("GET", "suggestion.php?q=" + q, false); ajax.send(); } </script> <script> function validateForm() { var x=document.forms["q"]["q"].value; if (x==null || x=="") { return false; } } </script> </head> <body> <form method="GET" action="search.php" name="q" onsubmit="return validateForm()"> <table align="center"> <tr> <td> <h1><center>Brandon's Search Engine</center></h1> </td> </tr> <tr> <td align="center"> <input type="text" name="q" style="height: 27px; width: 650px; padding: 2px" onkeyup="getSuggestion(this.value)" autocomplete="off" onblur="blur() document.getElementById('suggestion').style.visibility = 'hidden'"/> <div id="suggestion" style="width: 648px"> </div> </td> </tr> <tr> <td align="center"> <input type="submit" name="submit" value="Search" style="height: auto; width: 60px; padding: 2px" /> <input type="reset" value="Clear" style="height: auto; width: 50px; padding: 2px" /> </td> </tr> <tr> <td align="center"> To insert your site in result fill in the form at <a href="insert.php">here</a>. </td> </tr> </table> <input type="hidden" name="page" value="0" /> </form> </body> </html> Thanks
  2. I have received an error when I run this code: Parse error: syntax error, unexpected 'while' (T_WHILE) in C:\wamp\www\SearchEngine\search.php on line 50 Code: <?php //php code goes here include 'connect.php'; // for database connection $query = $_GET['q'] // query ?> <html> <head> <title> Brandon's Search Engine </title> <style type="text/css"> #search-result { font-size: 22; margin: 5px; padding: 2px; } #search-result:hover { border-color: red; } </style> </head> <body> <form method="GET" action="search.php"> <table> <tr> <td> <h2> Brandon's Search Engine </h2> </td> </tr> <tr> <td> <input type="text" value="<?php echo $_GET['q']; ?>" name="q" size="80" name="q"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <?php //SQL query $stmt = "SELECT * FROM web WHERE title LIKE '%$query%' OR link LIKE '%$query%'"; $result = mysql_query($stmt); $number_of_result = mysql_num_rows($result); if($number_of_result < 1) echo "No result found. Please try with other keyword."; else ( //results found here and display them while($row = mysql_fetch_assoc($result)) ( $title = $row["title"]; $link = $row["link"]; echo "<div id='search-result'>"; echo "<div id='title'" . $title . "</div>"; echo "<br />"; echo "<div id='link'" . $link . "</div>"; echo "</div>"; ) ) ?> </td> </tr> </table> </form> </body> </html> Thanks.
×
×
  • 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.