dongzhi4470
2015-11-10 12:02
浏览 53
已采纳

使用'select'选项提供输出[关闭]

just looking for some quick help.

I'm building an online solution for downloads, but I'm a but unsure as to how or what solution to use. below is an example of what I'm aiming for.

<select id="choice1">
<option value="tea">tea</option>
<option value="coffee">coffee</option>
</select>

<select id="choice2">
<option value="1">Milk</option>
<option value="2">Sugar</option>
<option value="3">Honey</option>

</select>

<select id="choice3">
<option value="yes">YES</option>
<option value="no">no</option>

</select>

<button type="button">Generate</button>

<p>You need to install the following:</p>

[LIST ITEMS CHOSEN HERE]

The user would select, an option from the first ID, then an option from the second and third and then based on their options, would be given the download links to what they need to download.

Would I use Php for this? If so, could anyone provide examples?

Thanks a lot!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doutang1856 2015-11-10 12:21
    已采纳

    Actually you can use Javascript unless you need to do something on your server (PHP). I made a little example of getting the values from all selects, so now you can just made the download link using this values or send them to your server using AJAX, and then return the links from the server.

    example (I've added an id to your button called btn):

    var btn = document.getElementById("btn");
    btn.addEventListener("click",function(){
        var op1 = document.getElementById("choice1");
        var op2 = document.getElementById("choice2");
        var op3 = document.getElementById("choice3");
        v1 = op1.options[op1.selectedIndex].value;
        v2 = op2.options[op2.selectedIndex].value;
        v3 = op3.options[op3.selectedIndex].value;
        // do what you want with the three values
    });
    

    Running here: http://jsfiddle.net/mvt421ok/

    Add alerts for v1, v2 and v3 if you want.

    If that's not what you need, try to ask me and I would edit this answer.

    Edit1: example with dynamic URL update: http://jsfiddle.net/mvt421ok/2/

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongqian9567 2015-11-10 12:10

    Yes you can use PHP for this. you need to perform query to selected customized records of your downloads according to user choice. May be it is not exact that you want but following is similar example fro where you can understand. link is Here

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题