0

我想单击图像并重定向到具有子域 $platform 和过滤器 $search_filter 的 url。这就是我到目前为止所拥有的。请帮忙?

<head>
<script>      
  function search_platform() {
    var $platform=document.getElementById("search_platform").value;
    var $search_filter=document.getElementById("search_filter").value;
    if ($platform !== '0') {
      document.location.href='http://www.' + $platform + 'domain.com/index.php?filter_name=' + $search_filter;
    }
  }
</script>
</head>
<body>

  <select id="search_platform">
    <option value="0" selected="selected"><?php echo 'Select Platform'; ?></option>
    <option value="platform1">Platform 1</option>
    <option value="platform1">Platform 1</option>
    <option value="platform1">Platform 1</option>
  </select>
  <input type="text" name="filter_name"/>
  <img src="test.png" width="264" height="110"  onclick="search_platform()"/>

</body>
4

4 回答 4

1

试试这个 :

    <head>
    <script>      
      function search_platform() {
       //Removed $ from variables name
        var platform=document.getElementById("search_platform").value;
        var search_filter=document.getElementById("search_filter").value;
        if (platform !== '0') {
          document.location.href='http://www.' + platform + 'domain.com/index.php?filter_name=' + search_filter;
        }
      }
    </script>
    </head>
    <body>

      <select id="search_platform">
        <option value="0" selected="selected"><?php echo 'Select Platform'; ?></option>
        <option value="platform1">Platform 1</option>
        <option value="platform1">Platform 1</option>
        <option value="platform1">Platform 1</option>
      </select>
      <input type="text" name="filter_name" id="search_filter"/> <!-- Added id -->
      <img src="test.png" width="264" height="110"  onclick="search_platform()"/>

    </body>
于 2012-11-30T03:43:47.687 回答
0

您在输入字段中缺少 ID:

<input type="text" name="filter_name" id="search_filter"/>
于 2012-11-30T03:43:56.640 回答
0

我认为您的问题是从选择元素中获得价值。试试下面

<script>      
  function search_platform() {
    var $platform=document.getElementById("search_platform").value;
    var $selectedplatform = platform.options[platform.selectedIndex].value;
    var $search_filter=document.getElementById("search_filter").value;
    if ($platform !== '0') {
      document.location.href='http://www.' + $selectedplatform + 'domain.com/index.php?filter_name=' + $search_filter;
    }
  }
</script>
于 2012-11-30T03:44:06.677 回答
0

我尝试修改您的所有代码以使其更加标准。

<head>
   <script type="text/javascript">
      function search_platform() {
         var platform=document.getElementById("search_platform").value;
         var search_filter=document.getElementById("search_filter").value;
         if (platform !== '0') {
            document.location.href='http://www.' + platform + '.domain.com/index.php?filter_name=' + search_filter;                                                                        
         }
      }
  </script>
</head>
<body>
   <select id="search_platform">
      <option value="0" selected="selected"><?php echo 'Select Platform'; ?></option>
      <option value="1mmtform1">Platform 1</option>
      <option value="platform2">Platform 2</option>
      <option value="platform3">Platform 3</option>
   </select>
   <input type="text" name="filter_name" id="search_filter"/>
   <img src="test.png" width="264" height="110" onclick="javascript:search_platform()" />
 </body>
于 2012-11-30T04:06:13.977 回答