最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make to submit button, delete and update at the same form,php - Stack Overflow

programmeradmin0浏览0评论

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...

<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

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...

<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

Share Improve this question edited Feb 15, 2014 at 19:20 Philip G 4,1042 gold badges24 silver badges42 bronze badges asked Feb 15, 2014 at 19:16 user3272713user3272713 1672 gold badges5 silver badges15 bronze badges 2
  • you can write an intermediate.php which decides which place to navigate based on the button clicked. Something like if buttonClicked = 'delete' then goto delete.php else goto update.php – Habrashat Commented Feb 15, 2014 at 19:19
  • do not use <input type="button"... add simply delete link to the table cell... the link is not related the form. you will get simly $_GET value(row id) from url and if isset delete related row – optional Commented Feb 15, 2014 at 19:33
Add a ment  | 

3 Answers 3

Reset to default 2

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>

and then at your "delete.php" page check which one of them you want to

if($_POST['send']=='update')
{ UPDATE table_name SET id='Your_ID' } 
else 
{DELETE FROM table_name WHERE id='Your_ID'}

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

 if(isset($_POST['delete']){
     //Delete was triggered
 }
 else{
     //Delete wasn't
 }

with jquery you can also change the actual file. Like this

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");
        }
 });

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" >

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论