douba4275 2017-06-26 07:47
浏览 30
已采纳

如何从所选项目选项生成大多数出现值的递增列表?

I have a form that has two event options, each event has 3 different items each and each item has 2-3 participants.

Event 1

  1. Football – John, Mike, Sam
  2. Cricket – Sam, Henry
  3. Chess – Ross,Mike

Event 2

  1. Guitar – Sam, Phillip
  2. Drum – Steve, Ross
  3. Piano – Mike, John
<form>
    <div>
        <h1>Select Event 1</h1>
        <select>
            <option>Football</option>
            <option>Cricket</option>
            <option>Chess</option>
        </select>
    </div>
    <div>
        <h1>Select Event 2</h1>
        <select>
            <option>Guitar</option>
            <option>Drum</option>
            <option>Piano</option>
        </select>
    </div>
    <input type="submit" /> 
</form>

How do I generate a result that makes a list of people who are involved on those selected items and he who has maximum participation among those events appears first and then the rest. Like, when someone selects 'Football' from Event 1 and 'Guitar' from Event 2, after submission, the result will be –

Participants

  1. Sam
  2. Henry, Phillip

How do I set the values of the options and how php or javascript can help me generate the result?

  • 写回答

1条回答 默认 最新

  • doumi9661 2017-06-26 08:04
    关注

    You can set an array of object for map your participants with the events. Here is a logic who can be implemented. It works for one event selection. You just have to loop into each select.

    var participants = [{
      name:"Sam",
      events:["Football","Guitar"]
    },{
      name:"Philip",
      events:["Drum","Cricket","Guitar"]
    }];
    
    $(".event-selection").change(function(){
      var selectedEvent = $(this).find("option:selected").text();
      var results = participants.filter(function(p){
        return p.events.indexOf(selectedEvent) > -1;
      }).map(function(p){return p.name}).join(", ");
      $(".results").text(results);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <form>
        <div>
            <h1>Select Event 1</h1>
            <select class="event-selection" id="event1">
                <option>Football</option>
                <option>Cricket</option>
                <option>Chess</option>
            </select>
        </div>
        <div>
            <h1>Select Event 2</h1>
            <select class="event-selection" id="event2">
                <option>Guitar</option>
                <option>Drum</option>
                <option>Piano</option>
            </select>
        </div>
    </form>
    <div class="results">
    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀