下拉菜单中的多项操作

时间:2019-05-06 04:04:28

标签: javascript php html

我有一个下拉菜单,它将具有多种功能。

  • “更新”将您带到页面以更新信息
  • “导出表单”将您带到页面以导出表单

**以上两种操作都可以使用当前代码完成。我遇到的问题是允许下拉菜单也通过onclick打开模式。

  • “删除课程”打开模式
  • “查看评论”打开模式

我已经使用onchange="location=this.value;"打开了不同的页面。但是,我似乎无法弄清楚如何在同一下拉列表中同时允许onchange="location=this.value;"onclick

我的代码:

<select class="form-control noform" onchange="location=this.value;">
  <option selected="true" disabled="disabled">
    <h6>ACTIONS &#10010;</h6>
  </option>
  <option value="edit_course?person_id=<?php echo htmlentities ($row['id']) ?>&session_id=<?php echo $_GET['session_id'] ?>&operation=edit">UPDATE</option>
  <option value="export?person_id=<?php echo htmlentities ($row['id']) ?>&session_id=<?php echo $_GET['session_id'] ?>&operation=edit">EXPORT FORM</option>
  <option onclick="deleteCourse()">DELETE COURSE</option>
  <option onclick="openModal()">VIEW COMMENTS</option>
</select>

1 个答案:

答案 0 :(得分:1)

尝试一下

<select class="form-control noform" onchange="doAction(this.value);">
  <option selected="true" disabled="disabled">
    <h6>ACTIONS &#10010;</h6>
  </option>
  <option value="update">UPDATE</option>
  <option value="exportForm">EXPORT FORM</option>
  <option value="deletCourse">DELETE COURSE</option>
  <option value="viewComments">VIEW COMMENTS</option>
</select>

JS:

  

在js中,您需要对重定向和打开模式进行一些尝试和错误的事情

function doAction(value){
  switch (value) {
      case "update":
          //edit_course?person_id=<?php echo htmlentities ($row['id']) ?>&session_id=<?php echo $_GET['session_id'] ?>&operation=edit
          //here you can do your update redirection
          break;
      case "exportForm":
          //export?person_id=<?php echo htmlentities ($row['id']) ?>&session_id=<?php echo $_GET['session_id'] ?>&operation=edit
          //here you can do your export redirection
          break;
      case "deletCourse":
          deleteCourse();//here you can open your modal
          break;
      case "viewComments":
          openModal();//here you can open your modal
          break;
  }
}