我想点击图片并重定向到具有子域$ platform并过滤$ search_filter的网址。这就是我到目前为止所拥有的。请帮忙吗?
<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>
答案 0 :(得分: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>
答案 1 :(得分:0)
您在输入字段中缺少ID:
<input type="text" name="filter_name" id="search_filter"/>
答案 2 :(得分:0)
我认为您的问题是从select元素中获取价值。尝试以下
<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>
答案 3 :(得分: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>