我有这个表单,现在需要在用户选择游戏类型和插槽后按下名为" buynow.png"的图像按钮创建重定向。
如果用户选择" public"他将被重定向到" www.domain.com/public.html" ;,否则,如果它是"私人"转到" www.domain.com/private.html"
这里是实际代码
<div>
<form name="f1">
<div>
<select name="server_type" onchange="change_selection()">
<option value="0" selected>Select</option>
<option value="1">Public</option>
<option value="2">Private</option>
</select>
</div>
<div>
<select name="server_slots">
<option value="-">-</option>
</select>
</div>
<div>
<a><img src="images/bBuyNow.png" border="0" /></a>
</div>
</form>
<script language="javascript" type="text/javascript">
var slots_1=new Array("10 Players","11 Players","12 Players")
var slots_2=new Array("10 Players","11 Players","12 Players")
function change_selection(){
var server_type
server_type = document.f1.server_type[document.f1.server_type.selectedIndex].value
if (server_type != 0) {
slots_selected=eval("slots_" + server_type)
cant_slots = slots_selected.length
document.f1.server_slots.length = cant_slots
for(i=0;i<cant_slots;i++){
document.f1.server_slots.options[i].value=slots_selected[i]
document.f1.server_slots.options[i].text=slots_selected[i]
}
}else{
document.f1.server_slots.length = 1
document.f1.server_slots.options[0].value = "-"
document.f1.server_slots.options[0].text = "-"
}
document.f1.server_slots.options[0].selected = true
}
</script>
</div>
提前致谢。
答案 0 :(得分:0)
我不知道你在使用插槽做什么,但是对于重定向,你可以使用window.location.href
<div>
<form name="f1">
<div>
<select name="server_type" onchange="change_selection()">
<option value="0" selected>Select</option>
<option value="1">Public</option>
<option value="2">Private</option>
</select>
</div>
<div>
<select name="server_slots">
<option value="-">-</option>
</select>
</div>
<div>
<a><img src="images/bBuyNow.png" border="0" href="javascript:viod(0)" onclick="redirecturl();"/></a>
</div>
</form>
<script language="javascript" type="text/javascript">
var slots_1=new Array("10 Players","11 Players","12 Players");
var slots_2=new Array("10 Players","11 Players","12 Players");
function redirecturl(){
var server_type;
server_type = document.f1.server_type[document.f1.server_type.selectedIndex].value;
var selectedslot = document.f1.server_slots[document.f1.server_slots.selectedIndex].value;
if (server_type == 1) {
window.location.href="www.domain.com/public.html?slot="+selectedslot ;
}
}else if(server_type == 2){
window.location.href="www.domain.com/private.html?slot="+selectedslot;
}
else{
alert('please select a value');
return;
}
}
</script>
</div>