搜索选项主要有以下内容和功能如下,下拉列表中有“产品”和“资料”选项,后面是输入文本框和提交按钮,如何实现在选择“产品”点击按钮时是就搜索“产品”,而在选择“资料”点击按钮时时就搜索“资料”,这应该是很简单的问题,怎么搞,我主要是不熟悉JavaScript代码?
<html>
<head>
<title>选择搜索CsrCode.Cn</title>
</head>
<body>
<form>
<select name="">
  <option>产品</option>
  <option>资料</option>
</select>
<input name="" type="text" />
<input name="" type="button" />
</form>
</body>
</html>

解决方案 »

  1.   


    <html>
    <head>
    <title>选择搜索CsrCode.Cn</title>
    <script language="javascript" type="text/javascript">
    function huihui()
    {
    alert("aa");
    var textattr=document.getElementById("kk");
    var sellectattr=document.getElementById("fun");
    alert(sellectattr.length);
     for(var i=0;i<sellectattr.length;i++)
    {
             if(sellectattr[i].selected==true)
    {
       
       textattr.value=sellectattr[i].innerHTML; 
     }
     
     }
     alert("aa");
    }</script>
    </head>
    <body>
    <form>
    <select name="" id="fun">
      <option></option>
      <option>产品</option>
      <option>资料</option>
    </select>
    <input name="" type="text" id="kk"/>
    <input name="" type="button" onclick="javascript:huihui();"/>
    </form>
    </body>
    </html>
      

  2.   

    和JavaScript没什么关系,在后台判断...
      

  3.   

    我的意思是选择“产品”点击提交按钮时,就能跳转和传递参数到productsearch.php;选择“资料”是datasearch.php,一楼朋友可能误会了
      

  4.   

    那还是判断你是选择的“产品”还是“资料”,虽然1楼做的方法不是你要的,至少你知道了怎么去判断。
    那么你只要根据当前选择把转跳和传递参数,传递到对应php不就ok了。就是if判断么。
      

  5.   

    这和JS没关系,根本用不着写一句JS.只是HTML的事.
    你的基础目前缺乏得太多,不是能靠问问题解决的,最好先看看系统的开发书籍(我感觉我都快成图书义务宣传员了).
      

  6.   

    <form action="search.php" method="post">
    <select name="skind">
      <option>产品</option>
      <option>资料</option>
    </select>
    <input name="" type="text" />
    <input name="" type="button" />
    </form>后台PHP里:
    <?php echo $_POST["skind"]; ?>楼主下面说的,提交到不同的PHP页面.这个是很笨的方法.学PHP,应该学到模板和控制器.提交到同一个控制器页面,按照行为参数,由这个控制器页面再去调用相应的行为,在里面再读取相应模板.这样,维护的时候,只需要修改这个控制器,而无需再改动HTML.
      

  7.   

    <html>
    <head>
    <title>选择搜索CsrCode.Cn</title>
    <script language="javascript" type="text/javascript">
    function huihui()
    {
       
    var textattr=document.getElementById("kk");
    var sellectattr=document.getElementById("fun"); for(var i=0;i<sellectattr.length;i++)
        {
             if(sellectattr[i].selected==true)
            {
               
               if(sellectattr[i].innerHTML=='产品')
    {
         window.location.href="b.php?attr="+textattr.value;
       }
       else if(sellectattr[i].innerHTML=='资料')
    {
         window.location.href="c.php?attr="+textattr.value;
       }
             }
     
     }}</script>
    </head>
    <body>
    <form>
    <select name="" id="fun">
      <option></option>
      <option>产品</option>
      <option>资料</option>
    </select>
    <input name="" type="text" id="kk"/>
    <input name="" type="button" onclick="javascript:huihui();"/>
    </form>
    </body>
    </html>
    b.php/c.php
    <?phpprint_r($_GET);
    ?>
      

  8.   

    我按照笨办法做了一个:<html>
    <head>
    <title>多搜索跳转</title>
    </head>
    <body>
    <form id="mainform" name="mainform" method="post" action="?">
      <label>
      <input name="mkey" type="text" id="mkey" value="" />
      </label>
      <label>
      <select name="allsear" id="allsear">
        <option value="1">产品</option>
        <option value="2">资料</option>
      </select>
    </label>
      <label>
      <input type="button" name="button" id="button" value="搜索" onClick="subs();" />
      </label>
    </form>
    <script>
    function subs()
    {
      var myvalue=document.getElementById("allsear").options[document.getElementById("allsear").selectedIndex].value;
      var keytext=document.mainform.mkey.value;
      var urls;
      switch(myvalue)
      {
      case "1":
      urls="http://localhost/ctdeb/product.php?kind=%25&brand=%25&kws="+keytext;
      break
      case "2":
      urls="http://localhost/ctdeb/data.php?kind=%25&kws="+keytext;
      break}
    window.location.href=urls;
    }
    </script>
    </html>