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

使用'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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题