2013-02-25 59 views
-1

我有一个带有几个单选按钮的表单,我想使用单选按钮选择的值来更改单击某个按钮时要转到的网址。如何在按钮URL中使用单选按钮值?

<input type="radio" name="Server" value="ftp://one.com" checked>One 
<input type="radio" name="Server" value="ftp://two.com">Two 


<button type="button" name="" onClick="location.href='document.getElementsByName("Server").checked + "/file.ext"'">Download 

我想用单选按钮选择FTP服务器并更改按钮的下载链接。

+1

whathaveyoutried.com? – 2013-02-25 18:54:00

+2

你在哪里遇到麻烦?你可以发布迄今为止已经尝试过的代码吗(或者如果你不确定如何编写代码,你是如何去考虑的?)? – 2013-02-25 18:55:53

+0

我发布了代码,但它只是作为文本出现,直到我在 – Siecje 2013-02-25 18:57:52

回答

0
<script> 
function getServer() { 
    var servers = document.getElementsByName("Server"); 
    for(var i = 0; i < servers.length; i++) { 
     if (servers[i].checked) { 
      return servers[i].value; 
     } 
    } 
    return ''; 
} 
</script> 

<input type="radio" name="Server" value="ftp://one.com" checked>One 
<input type="radio" name="Server" value="ftp://two.com">Two 


<button type="button" id="courseware" onClick="location.href= getServer() + '/file.ext'">Download 
1

我相信它应该是

document.getElementsByName("Server").checked 

你错过了一个 'e' ......

相关问题