-1

Нашел в интернете скрипт на Javascript. Что-то типо поисковика. Проблема в том, что при вводе пустого запроса, скрипт отображает все имеющиеся запросы. Как можно сделать так, чтобы скрипт не отображал ничего при вводе пустого запроса?

<!-- 2000 copyright AML development -->

<HTML>
<HEAD>
	<TITLE>Scriptsnetwork ::: ���������������� ������</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">


</HEAD>
<style type="text/css">
A:link	 	{ color: #003399; text-decoration: underline	}
A:visited	{ color:#003399;	text-decoration: underline	}
A:hover		{ color:#003399; text-decoration: none      }
.copy	 {  font: 8pt/normal  Verdana, Arial, Helvetica, sans-serif; text-transform: super; text-decoration: none; color: #333333}
.copy1	 {  font: bold 10pt/normal  Verdana, Arial, Helvetica, sans-serif; text-transform: super; text-decoration: none; color: #333333 }
.copy2	 {  font: 9pt/normal  Verdana, Arial, Helvetica, sans-serif; text-transform: super; text-decoration: none; color: #333333 }

</style>
<BODY bgcolor="#FFFFFF">
<div align="center">
<table border="0" width="500" cellspacing="0" cellpadding="0">
<tr>
    <td><a href="http://www.cgi.ru"><img src="topl.gif" width=500 height=29 border=0 alt="Scriptsnetwork"></a></td>
</tr>
</table>
<table border="0" width="500" cellspacing="2" cellpadding="2">
<tr>
    <td align="center" class="copy1" valign="top">
	���������������� ������!
	</td>
</tr>
<tr>
    <td class="copy2" valign="top">
	<br><br><br>
<script language="javascript">
        var key = "";
        function makeEntry (){
                this.Date = "";
                this.Name="";
                this.URL = "";
                this.Desc = "";
                this.Category = "";
                return this;
        }
 function makeArray(n) {
                this.length = n;
                for (var k = 1; k <= n; k++) {
                                this[k] = "";
                }
                return this;
        }               
        function makeLinks(size) {
                                this.length = size;
                                for (var r=1; r<= size; r++) {
                                                        this[r] = new makeEntry();
                                                        this[r].Date = datesArray[r];
                                                        this[r].Name = namesArray[r];
                                                        this[r].URL = urlsArray[r];
                                                        this[r].Desc = descArray[r];
                                                        }
                                        return this;
                        }
var linksize=0 
datesArray = new makeArray(linksize);
namesArray = new makeArray(linksize);
urlsArray = new makeArray(linksize);
descArray = new makeArray(linksize);
var arraycount=0

/*����� ���������� �������� ������ � ���� */
arraycount += 1 
/* ���� �������� */
datesArray[arraycount] = "1/1/97 "
/* ����� � �������� */
urlsArray[arraycount] = "http://www.yahoo.com"
/* �������� */
namesArray[arraycount] = "Yahoo"
/* �������� */
descArray[arraycount] = "������ � ����� ������� ������� ��������"
/* � ��� ����� */
//alert(arraycount)
arraycount += 1 
datesArray[arraycount] = "1/1/97 "
urlsArray[arraycount] = "http://www.lycos.com"
namesArray[arraycount] = "Lycos"
descArray[arraycount] = "������� ��������� �������"
//alert(arraycount)
arraycount += 1 
datesArray[arraycount] = "1/1/97 "
urlsArray[arraycount] = "http://www.webcrawler.com"
namesArray[arraycount] = "Webcrawler"
descArray[arraycount] = "�������� ���������"
//alert(arraycount)
arraycount += 1 
datesArray[arraycount] = "1/1/97 "
urlsArray[arraycount] = "http://www.search.com"
namesArray[arraycount] = "Search.com"
descArray[arraycount] = "��������� ����� ��������� ������."
//alert(arraycount)
arraycount += 1 
datesArray[arraycount] = "1/1/97 "
urlsArray[arraycount] = "http://altavista.digital.com"
namesArray[arraycount] = "AltaVista"
descArray[arraycount] = "� ���� ��������� ������� ����� ������� ���� ������"
//alert(arraycount)
linksize = arraycount;
// ----end data -------
function showAll(linkobj) {
                for (var s=1; s<= linkobj.length; s++) {
                                               showLink(linkobj,s);
                                }
                        }
function showLink (links, index) {
        //document.write("<table border=1>");
        document.write("<tr><td class='copy2'>" + links[index].Date +"</td>");
        document.write("<td class='copy1'><a href=" + links[index].URL +">" + links[index].Name + "</a></td>");
        document.write("<td class='copy2'>" + links[index].Desc + "</td></tr>");
        //document.write("</table>");
        }
function searchLinks(links, keyword){
        document.write("��������� ������ ���: " +keyword +"<br>");
        document.write("<table>");
        for (var q=1; q<=links.length; q++) {
                        //document.write(q+".")
                        if (links[q].URL.indexOf(keyword) != -1){
                        //      document.write("��������� ������ ���: "+keyword+ "<br>" +links[q].Name +"<p>")
                        //document.write("��������� ������ ���:  "+keyword+ "<br>" );
                                showLink(links,q);
                                continue;
                        }
                        if (links[q].Desc.indexOf(keyword) != -1) {
                                        showLink(links,q);
                                continue;
                        }
                        if (links[q].Date.indexOf(keyword) != -1) {
                                        showLink(links,q);
                                continue;
                        }
                        if (links[q].Name.indexOf(keyword) != -1) {
                                        showLink(links,q);
                                        continue;
                        }
                }
        document.write("</table>");
        }                                       
// final stuff
// the main program ---
jsi = new makeLinks(linksize);
document.write("<title>��������� ������</title><body bgcolor=white>");
searchLinks(jsi, prompt("������� �����:) \r����� � ����:","�����, �����, �����, ����"));
document.write("<hr>");
document.write("����� ���������� �� ���� �������");
document.write("<form><input type=button onClick='history.go(0)' value='������ �����'></form>");
// show all the links
//document.write("<table border>");
//showAll(jsi);
//document.write("</table>");
</script>

	<br><br><br>
	</td>
</tr>
</table>
<table border="0" width="500" cellspacing="2" cellpadding="2">
<tr>
    <td align="center" class="copy" valign="top">
	<hr noshade size="1">
	<a href="http://www.cgi.ru">�������� ��� ������ � ����������� �� ���� ��������!</a>
	<hr noshade size="1">
2000 Copyright &copy <a class="copy" href="http://www.cgi.ru">scriptsnetwork</a>. All rights reserved.<br>
	</td>

</tr>
</table>


</div>
</BODY>
</HTML>

1 ответ 1

0

используйте на поле ввода .trim() и проверяйте это поле.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.