Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  118] [ 4]  / answers: 1 / hits: 17513  / 11 Years ago, sun, october 6, 2013, 12:00:00

I am trying to create drop down menu with a button.



My code is -



<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 now </a>
</div>


Depending on what option i select from dropdown, the href value somelink should change.
For instance if i select 1 year. href value should change from somelink to google.com



Update:



I searched two things. 1) Changing href using javascript and 2) using onchange for select tag. It lead me to create this 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 now </a>
</div>


Problem: The drop down shows 3 years by default. But if i select 2 years, it still remains 3 years.


More From » html

 Answers
6

Try this to change the href to the value of the 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 now </a>
</div>


Javascript



var sel = document.getElementById('basic_plan');
sel.onchange = function () {
document.getElementById(abc).href = this.value + .html;
}


Demo here


[#75189] Friday, October 4, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sonja

Total Points: 541
Total Questions: 113
Total Answers: 114

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
sonja questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Sun, Nov 10, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;