javascript - How to change href link of button used with dropdown menu? -
i trying create drop down menu button.
my code -
<div class="dropdown-plans"> <select id="basic_plan" name="bill_cycle"> <option value="tri"> 3 years - rs. 100/month </option> <option value="bi"> 2 years - rs. 200/month </option> <option value="ann"> 1 year - rs. 100/month </option> </select> </div> <div class="button-plans"> <a href="somelink"> order </a> </div>
depending on option select dropdown, href value "somelink" should change. instance if select 1 year. href value should change "somelink" "google.com"
update:
i searched 2 things. 1) changing href using javascript , 2) using onchange select tag. lead me create following piece of code.
<script> function getopt(period) { if (period.value = "tri") { document.getelementbyid("abc").href="tri.html"; } else if (period.value = "bi") { document.getelementbyid("abc").href="bi.html"; } else { document.getelementbyid("abc").href="ann.html"; } } </script> <div class="dropdown-plans"> <select id="basic_plan" name="bill_cycle" onchange="getopt(this)"> <option value="tri"> 3 years - rs. 100/month </option> <option value="bi"> 2 years - rs. 200/month </option> <option value="ann"> 1 year - rs. 100/month </option> </select> </div> <div class="button-plans"> <a id="abc" href="something"> order </a> </div>
problem: drop down shows 3 years default. if select 2 years, still remains 3 years.
try change href
value of selected option:
html
<div class="dropdown-plans"> <select id="basic_plan" name="bill_cycle"> <option value="tri">3 years - rs. 100/month</option> <option value="bi">2 years - rs. 200/month</option> <option value="ann">1 year - rs. 100/month</option> </select> </div> <div class="button-plans"> <a id="abc" href="something"> order </a> </div>
javascript
var sel = document.getelementbyid('basic_plan'); sel.onchange = function () { document.getelementbyid("abc").href = this.value + ".html"; }
Comments
Post a Comment