您的位置:首页 > 编程语言 > PHP开发

Java Script与PHP配合实现智能化的搜索界面

2004-10-07 19:45 507 查看

Java Script与PHP配合实现智能化的搜索界面

<?php
  require("inc/conn.inc");  //连接数据库
?>

<html>
<head>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE>深圳个体私营企业在线</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
</head>
<BODY>
<link rel="stylesheet" href="inc/index.css" type="text/css">
<script language="JavaScript">
<!--
function leftcheck(theForm)
{
  with(theForm){
  if (s_type.value == "")
  {
    alert("非常抱歉!如果您希望执行搜索功能/n请先选择搜索类别!");
    s_type.focus();
    return (false);
  }
  if ((sub_type.options[0].text=="无子项目/可选")&&((key.value == "")||(key.value == "请输入关键字")))
  {
    alert("抱歉!由于没有指定子项目,您必须输入有效的关键字!");
    key.value="";
    key.focus();
    return (false);
  }
  if ((key.value == "请输入关键字")||(key.value == "/可输入公司名"))
  {
    alert("抱歉!您输入了错误的关键字!");
    key.value="";
    key.focus();
    return (false);
  }
  }
}
function chgitem(sel_func)
{
  var func=sel_func;
  switch (func) {
  case "company":
    search.key.value="/可输入公司名";
    search.sub_type.options[0].text="/可继续选行业";
    search.sub_type.options[0].value="";
    <?
      //取出公司分类的样本数据
      $querytype = "SELECT * FROM sample Where Sample_Type='Company'";  
      $resultType = mysql_query($querytype);
      $numRows = mysql_num_rows($resultType);
      echo 'search.sub_type.options.length='.($numRows+1).';'.chr(13).chr(10);
      for($i=0 ; $i < $numRows; $i++) {
        $rowType = mysql_fetch_array($resultType);
        $d_value=$rowType["Sample_Value"];
        if (strlen($d_value) >12) {
          $d_value=substr($d_value,0,10)."..";
        }
        echo '    search.sub_type.options['.($i+1).'].text="'.$d_value.'";'.chr(13).chr(10);
        echo '    search.sub_type.options['.($i+1).'].value="'.$rowType["Sample_ID"].'";'.chr(13).chr(10);
      }
    ?>
    break;
  case "forum":
    search.key.value="请输入关键字";
    search.sub_type.options.length=1;
    search.sub_type.options[0].text="无子项目/可选";
    search.sub_type.options[0].value="";
    break;
  default:
    search.key.value="请选搜索类别";
    search.sub_type.options.length=1;
    search.sub_type.options[0].text="暂无子项目/可选";
    search.sub_type.options[0].value="";
  }
}
//-->
</script>
<form name=search action="serach.php" method="post">
<p>站内搜索:</p>
<p><select size=1 name=s_type OnChange=chgitem(this.value)>
  <option>选择搜索类别</option>
  <option value="company">会员企业搜索</option>
  <option value="forum">论坛搜索</option>
</select></p>
<p><select size=1 name=sub_type>
  <option>请先选择总类</option>
</select></p>
<p>输入搜索关键字<br>
<input maxlength=20 size=12 name=key onClick="Javascript:this.value='';">
</p>
<input type="submit" name="iE4" Value="go">
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息