MULTI Team
MULTI Team

Reputation: 43

How can I direct URL with dropdown & textbox with JavaScript / HTML

multiinc.xyz is going through a makeover.
In the header is a textbox with a dropdown as a form element, but the submission dose nothing.

Here is the following broken code

<!-- Script -->
<script>
function CheckPassword() {
  var input=document.type.input.value;
  location.href = dropdown+input+'/';
}
</script>
<!-- End Script -->

<!--FORM TEXT BOX -->
<form method="post" action="ingen_javascript.htm" 
  onsubmit="CheckPassword();return false;" name="type">
<pre>



    <!--Dropdown-->
    <div class="styled-select slate">
<select id="dropdown" class="dropdown" >
  <option value="http://vitemulti.weebly.com/">Vite</option>
  <option value="http://multi-napkin.weebly.com/page#">Napkin ID</option>
  <option value="http://">http://</option>
  <option value="">URL</option>
</select></div>
    <!--End-->

<input type="text" name="input" placeholder="multiinc.xyz" list="autocomplete" >


</pre>
<input type="submit" value="" 
  onclick="CheckPassword();return false;" style="height: 0px; width: 0px; border: none; padding: 0px;" hidefocus="true" onclick="move()">
</form>


<!--END FORM-->



In the code, id="dropdown" class="dropdown" (which is the dropdown box) have the value to tell the textbox what site to search. The textbox has the location href: dropdown+input which should go to the website provided in dropdown value plus the input query

For example, if it was on vite and i typed in 'google'

it should add http://vitemulti.weebly.com/ + google = http://vitemulti.weebly.com/google

Thanks heaps!

Upvotes: 0

Views: 168

Answers (1)

Aditia Pratama
Aditia Pratama

Reputation: 148

you can try like this

<script>
  function CheckPassword() {
    var input=document.type.input.value;
    var dropdown = document.getElementById("dropdown").value
    location.href = dropdown+input+'/';
  }
</script>

Upvotes: 3

Related Questions