javascript 如何在同一表单中提交按钮,删除和更新,php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21802345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make to submit button, delete and update at the same form,php
提问by user3272713
I am making a form that when user check one row with check button he can delete or update it...But only the delete button work.I dont know how to make two submit buttons in the same form. I want the delete button when pressed to go to delete.php and update button to go two update.php...Below is my form...
我正在制作一个表单,当用户用检查按钮检查一行时,他可以删除或更新它......但只有删除按钮有效。我不知道如何在同一个表单中制作两个提交按钮。我想要删除按钮时按下去delete.php 和更新按钮去两个update.php ......下面是我的表格......
<form name="form1" method="post" action="delete.php">
<table >
<th>
<th ><strong>Emri </strong></th>
<th ><strong>Pershkrimi </strong></th>
<th><strong>Ora</strong></th>
</th>
<?php
while ($row=mysql_fetch_array($result)) {
?>
<tr>
<td ><input name="checkbox[]" type="checkbox" value="<?php echo $row['Id_Akt']; ?>"></td>
<td style="font-size:0.9em"><?php echo $row['Emri']; ?></td>
<td ><?php echo $row['Pershkrimi']; ?></td>
<td><?php echo $row['Ora']; ?></td>
</tr>
<?php
}
?>
</table>
<input class="button" name="delete" type="submit" value="Fshij" style="margin-left:4%; margin-top:50px; width:15%">
<br>
<input class="button" name="update" type="button" value="Update" style="margin-left:4%; margin-top:20px; width:15%" >
</form>
Please help me.Thanks in advance
请帮助我。提前致谢
回答by Philip G
I dont know how to port them to different pages directly without javascript, but you can check if the delete button is pressed with php like this
我不知道如何在没有 javascript 的情况下将它们直接移植到不同的页面,但是您可以像这样检查是否使用 php 按下了删除按钮
if(isset($_POST['delete']){
//Delete was triggered
}
else{
//Delete wasn't
}
with jquery you can also change the actual file. Like this
使用 jquery,您还可以更改实际文件。像这样
Jquery
查询
$("input[type=submit]").click(function(e){
$(this).addClass("e-clicked");
});
$("form").submit(function(){
var vall = $(this).find(".e-clicked").attr("id");
if(vall == "DELETEID"){
$(this).attr("action", "deleteUrl.php");
}
else{
$(this).attr("action", "updateUrl.php");
}
});
回答by Elfentech
Refer this :
参考这个:
Multiple submit buttons php different actions
Put this script in your page :
将此脚本放在您的页面中:
<script>
function submitForm(action)
{
document.getElementById('form1').action = action;
document.getElementById('form1').submit();
}
</script>
Modify your input code :
修改您的输入代码:
<input class="button" name="delete" type="submit" onclick="submitForm('delete.php')" value="Fshij" >
<input class="button" name="update" type="button" onclick="submitForm('update.php')" value="Update" >
回答by Mohamed Fouad
you should change the values of your buttons like this
你应该像这样改变你的按钮的值
<button type="submit" name="send" value="delete"> delete </button>
<button type="submit" name="send" value="update">update</button>
<button type="submit" name="send" value="delete"> delete </button>
<button type="submit" name="send" value="update">update</button>
and then at your "delete.php" page check which one of them you want to
然后在您的“delete.php”页面检查您想要其中的哪一个
if($_POST['send']=='update')
{ UPDATE table_name SET id='Your_ID' }
else
{DELETE FROM table_name WHERE id='Your_ID'}