组合2个表单字段进行范围搜索

Combinig 2 form fields to do a range search

本文关键字:范围 搜索 字段 2个 表单 组合      更新时间:2023-09-26

我一直在尝试找到一种方法,将两个表单字段组合起来,创建第三个隐藏字段,作为数字范围搜索提交。我发现了许多使用javascript组合文本字段的例子,但未能使它们发挥作用,我将非常感谢任何关于我哪里出错或是否有简单方法的建议。

到目前为止,我拥有的低于

在头部

<script type="text/javascript">
  function combprice() {
    var lowprice = document.forms[0].lowprice.value;
    var highprice = document.forms[0].highprice.value;
    document.forms[0].price.value = lowprice + " " + highprice;
  }
</script>

然后形成

<FORM ACTION="cgi-bin/sales.cgi" METHOD="POST" name="search" id="search"><table width="220" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="91"  height="30"><div align="right">Make <span class="style4">:</span> </div></td>
    <td width="129">
      <div align="left">
        <input name="Make" type="text" size="13" />
      </div></td></tr>
  <tr>
    <td  height="30"><div align="right">Model  </div></td>
    <td>
      <div align="left">
        <input name="Model" type=text size="13" />
      </div></td></tr>
  <tr>
    <td  height="30"><div align="right">Min Price <span class="style4">:</span> </div></td>
    <td>
      <div align="left">
        <input id="lowprice" name="lowprice" type="text" size="13" maxlength="13" />
      </div></td></tr>
  <tr>
    <td  height="30"><div align="right">Max Price <span class="style4">:</span> </div></td>
    <td>
      <div align="left">
        <input id="highprice" name="highprice" type="text" size="13" maxlength="13" />
      </div></td></tr>
  <tr>
    <td colspan="2"><table width="220" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td  height="30"><div align="right">Price:</div></td>
        <td><input name="Price" type="text" id="Price" size="13" maxlength="13"></td>
      </tr>
      <tr>
        <td width="90"  height="30">&nbsp;</td>
        <td width="130"><div align="center"><input name="Submit" type="submit" id="OnSubmit" value="Search" onclick="combprice()">
        </div></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>

所有字段都不是必填字段。

我知道上述内容不包括<=或者=>元素,我只是没能走那么远。提前感谢

                Leo 

name="Price"document.forms[0].price 之间的大小写不匹配

与匹配时效果良好

DEMO