download1002
download1002
2016-07-15 09:18

我想通过管理面板下拉菜单启用或禁用“博客帖子”

已采纳

I want to enable or disable post by clicking drop down values. How can i do that?

<script>
  function disable(post)
  {
      if(post=="0")
           document.getElementById("status").disabled=true;
      else
          document.getElementById("status").disabled=false;
  }
</script>

<select name="status" id=<?= $row["id_post"] ?>  onChange="disable(this.value)">
  <option value="0">Status</option>
  <option name="enable"  id="enable"  value="1">Enable</option>
  <option name="disable" id="disable" value="0">Disable</option>
</select>

i have a field in my database table name "r_post" column name "status int(1)"

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dsh77114 dsh77114 5年前

    No need to use JavaScript for Enable and Disable as per your code.

    <select name="status">
      <option>Status</option>
      <option value="1" <?php ($row["status"]==1)?'selected':'' ?>>Enable</option>
      <option value="0" <?php ($row["status"]==0)?'selected':'' ?>>Disable</option>
    </select>
    
    点赞 评论 复制链接分享
  • dongmaopiao0901 dongmaopiao0901 5年前

    Edit Your Code Firstly you need to create a php action page, if you want to create this page, then you can write down the code into you same php file. then on select for select box you need to submit the form. Then action will be goes on same page and your update query will update your blog record. Your need to add your table id the in hidden input type so the query will get the exact address.

    <html>
        <head>
        <?php
          if(isset($_POST['status']))
          {
            $sql=mysql_query("update blog set status='".$_POST['Status']."' where id='".$_POST['id']."'");
            echo ("blog updated successfully");
          }
        ?>
        <title>Your Page name</title>
        </head>
        <body>
    
    <form name="myform" action="" method="post">
    <input type="hidden" name="id" value="<?php echo $row['id'];?>">
    <select name="status" id="status1" onchange="this.form.submit()">
      <option value="0">Status</option>
      <option name="enable"  id="1enable"  value="1">Enable</option>
      <option name="disable" id="1disable" value="0">Disable</option>
    </select>
    </form>
    </body>
    

    点赞 评论 复制链接分享