2选择选项组合值和链接

时间:2014-06-30 05:49:40

标签: javascript html html-select location-href

我需要合并两个值并链接到选定的网站。

离。 select> Google> select>Translate

加入两个值

T2 [translate] T1 [.google.com] = translate.google.com Go

JS

<script>
function goToNewPage() {
  var g=document.getElementById('target').value;
  {
    window.location.href = document.getElementById('target').value;
  } 
}
</script>

HTML

<form name="dropdown">                    
   <select name="selected" id="target2" >
      <option selected>Select...</option>
      <option value=".google.com/">Google</option>
      <option value=".search.com/">Bing</option>
   </select>

   <select name="selected" id="target" >
      <option selected>Select...</option>
      <option value="http://translate">Translate</option>
      <option value="http://translate/">Translator</option>
   </select>
   <input type="button" value="Go" onclick="goToNewPage(document.dropdown.selected)">
</form>

1 个答案:

答案 0 :(得分:1)

试试这个:

window.location.href = document.getElementById('target').value + document.getElementById('target2').value