I have a block of code in a page where a user has to select the package from available packages.
<a href="#block"> VVIP <a>
<a href="#block"> VIP <a>
<a href="#block"> Median <a>
<a href="#block"> General <a>
Based on the user selection I want to select a drop-down value in the form. The form is available on the same page.
<select>
<option selected="" value="Default">Select Package</option>
<option value="1">Kids Pass</option>
<option value="2">Single Adult Pass</option>
<option value="3">Couple Pass</option>
<option value="4">Single Day Pass</option>
</select>
please help me if any HTML or JavaScript solution.
答案 0 :(得分:1)
这就是您所需要的,您正在使用JS
寻找事件
function selectauto(nameofpackage)
{
var element = document.getElementById('packages');
element.value = nameofpackage;
}
&#13;
<a href="#block" onclick="selectauto(1)"> VVIP <a><br>
<a href="#block" onclick="selectauto(2)"> VIP <a><br>
<a href="#block" onclick="selectauto(3)"> Median <a><br>
<a href="#block" onclick="selectauto(4)"> General <a><br>
<select id="packages">
<option selected="" value="Default">Select Package</option>
<option value="1">Kids Pass</option>
<option value="2">Single Adult Pass</option>
<option value="3">Couple Pass</option>
<option value="4">Single Day Pass</option>
</select>
&#13;
希望这有帮助。
答案 1 :(得分:1)
您可以通过使用javascript
更改options.selectedIndex Dom属性来执行此操作
function selectOption(index){
document.getElementById("select_stuff").options.selectedIndex = index;
}
&#13;
<!--This will selectKids pass-->
<a href="#block" onclick="selectOption(1);"> VVIP <a>
<!--This will Single Adult pass pass-->
<a href="#block" onclick="selectOption(2);"> VIP <a>
<!-- This will select Default -->
<a href="#block" onclick="selectOption(0);"> Median <a>
<!-- This will select Single Day pass -->
<a href="#block" onclick="selectOption(4);"> General <a>
<select id="select_stuff">
<option selected="" value="Default">Select Package</option>
<option value="1">Kids Pass</option>
<option value="2">Single Adult Pass</option>
<option value="3">Couple Pass</option>
<option value="4">Single Day Pass</option>
</select>
&#13;