2 Select options Combine values and link

2019-06-01 11:31发布

问题:

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