doulin9679 2010-08-31 10:31
浏览 12
已采纳

检查单击了哪个按钮

I have a PHP generated form which consists of a list of items, each with a button next to them saying "Remove This" it outputs similar to below:

Item A - [Remove This]
Item B - [Remove This]
...

I wish to be able to click Remove This and it will detect which item it is, and then remove that from the database. Here's my code so far:

selectPlaces.php

<?php
include 'data.php';

mysql_connect($host, $user, $pass) or die ("Wrong Information");

mysql_select_db($db) or die("Wrong Database");

$result = mysql_query("SELECT * FROM reseller_addresses") or die ("Broken Query");
while($row = mysql_fetch_array($result)){
    $placeName = stripslashes($row['b_name']);
    $placeCode = stripslashes($row['b_code']);
    $placeTown = stripslashes($row['b_town']);
    $outputPlaces .= "<strong>$letter:</strong> $placeName, $placeTown, $placeCode <input type=\"button\" onclick=\"removePlace()\" value=\"Remove This\" /><br />";
}

mysql_close();
?>

Coupled with my admin.php

        <div id="content" style="display:none">
        Remove a Place<br><br>
        <?php include 'selectPlaces.php'; echo $outputPlaces; ?> 
        </div>

I know I need to add some javascript to detect which button is clicked but I can't seem to get it working. I tried modifying the onclick="removePlace()" by perhaps passing a variable in the function removePlace(placeID) or something like that, but I'm new to JavaScript and I have no idea how to receive this in the removePlace function.

  • 写回答

2条回答 默认 最新

  • dounao4179 2010-08-31 10:38
    关注

    This seems easier to do without JavaScript. For each entry instead of generating just a button, generate a form that posts to a PHP script that does the deleting.

    <form action="deletePlace.php?id=<?php echo $idOfThePlace?>">
    <input type="submit" value="Remove This" />
    </form>
    

    $idOfThePlace would be the ID with you use to identify the data row.

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

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考