Reputation: 402
I want to click on a image and redirect to a url that has the subdomain $platform and filter $search_filter. This is what i have so far. Help please?
<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>
Upvotes: 0
Views: 708
Reputation: 61
I try to modify all your code to make it more standard.
<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>
Upvotes: 0
Reputation: 2944
I think your issue is getting value from select element. try below
<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>
Upvotes: 0
Reputation: 6771
You're missing the ID in the input field:
<input type="text" name="filter_name" id="search_filter"/>
Upvotes: 0
Reputation: 5274
Try this :
<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>
Upvotes: 1