douweng7308 2016-04-23 10:44
浏览 34
已采纳

将数据发送到mysql表时,html按钮(onclick)无法正常工作

So I have a forms on a html page which retrieve data from a mysql table. The user can modify these data, or delete the entire row. I have a html button with functionality of deleting the entire row, and with that button I have a javascript function that displays a confirm pop up box confirming if the user wants to delete it. If they click yes then it is sent to another php page where the deletion is performed. The problem is when I click on the confirm box nothing happens, it just stays on the same page. Here is my html and javascript code:

<form class="form-inline" method=GET action="envoieModifierAlbumAdmin.php">
    <table class="table table-striped">
        <tr>
            <td><button type="button" class="btn btn-danger" onclick="verif()">Supprimer Cet Album</button>
            </td><td></td><td></td>
        </tr>

        <tr>
            <td><label for="exampleInputName2">id: </label>
                <input readonly type="text" class="form-control" value="<?php echo "$donnees[id]"?>" id="exampleInputName2" name="id">
            </td><td></td><td></td>
        </tr>
        <tr>
            <td><label for="exampleInputName2">Nom d'album: </label>
            <input type="text" class="form-control" id="exampleInputName2" name="titre" value="<?php echo "$donnees[titre]"?>"></td>
            <td></td><td></td>
        </tr>
    </table>
</form>
<script>
    function verif(){
        var x;
        if(confirm("Vous êtes sûr que vous voulez supprimer ce compte?") == true){
            document.location="supprimerAlbumAdmin.php?id=$_GET['id']";
        }
        else
    }
</script>

The only problem is with the button, the other parts of the table above are just to show an example of what the user is modifying. Thanks in advance!

  • 写回答

3条回答 默认 最新

  • duanseci1039 2016-04-23 11:07
    关注

    your value should be like this

    value="<?php echo  $_GET['id'] ?>"
    

    not like this

    value="<?php echo "$donnees[id]"?>"
    

    and change button type into submit

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script>
    
    
    function verif(){
        alert("hi");
            var x;
            if(confirm("Vous êtes sûr que vous voulez supprimer ce compte?") == true){
                
                //window.location.replace("https://google.com");
                //exit();
              return true;
              
            }
            else
              {
                
                return false;
                
                }
            
        }
    </script>
    <form class="form-inline" method="GET" action="envoieModifierAlbumAdmin.php">
        <table class="table table-striped">
    
    
            <tr>
                <td><label for="exampleInputName2">id: </label>
                    <input readonly type="text" class="form-control" value="" id="exampleInputName2" name="id">
                </td><td></td><td></td>
            </tr>
            <tr>
                <td><label for="exampleInputName2">Nom d'album: </label>
                <input type="text" class="form-control" id="exampleInputName2" name="titre" value=""></td>
                <td></td><td></td>
            </tr>
                  <tr>
                <td><button type="submit" class="btn btn-danger" onclick="verif()">Supprimer Cet Album</button>
                </td><td></td><td></td>
            </tr>
        </table>
    </form>

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看