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条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)