2 Select options Combine values and link

落爺英雄遲暮 提交于 2019-12-08 03:23:52

问题


I need to combine two values and link to the selected site.

ex. select> Google> select>Translate

join two values

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:


Try this:

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


来源:https://stackoverflow.com/questions/24483631/2-select-options-combine-values-and-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!