doucang2871 2013-08-01 16:12
浏览 17
已采纳

如何提交许多自动生成的表单之一的值

I have a table with many auto generated forms (there could literally be hundreds of forms). The code for that is php based and looks like this:

$cellPosition = 0;
$rowCounter = 1;
$infoCounter = 1;

for ($x=0;$x <= count($assetName);$x++)
{
    for ($i=0;$i < count($currentJobs);$i++)
    {
        $rowCounter= 1;
        if ($currentJobs[$i][0] == $table->getCellContents(0,$x))
        {

            for ($y =0; $y < $currentJobs[$i][10];$y++)
            {
                $rowCounter++;
            }
            $table->setCellAttributes ($rowCounter,$cellPosition,"id='jobCell' bgcolor = ". $currentJobs[$i][4].  " rowspan=" . $currentJobs[$i][9]);
            $table->setCellContents($rowCounter++,$cellPosition,
                                    "<form id='scheduleForm".$infoCounter++."' method='POST' action='../forms/updateJobForm.php'>".
                                    "<input type='hidden' name='jobInfo' value='" . $currentJobs[$i][1] . "'/>" . " " . "Job# (".$currentJobs[$i][2] . ")<br>" . $currentJobs[$i][3] .
                                    "</form>");
        }
            else
            {
                $rowCounter = 1;
            }
    }
    $cellPosition++;
}
echo $table->display();

I have the jobCell (a td element) bound to the following javascript/jquery code:

<script>
    $(document).ready(function()
    {
        $("#jobCell").click(function()
        {
            $(this).children('form').submit();
            //$('#scheduleForm').submit();
        });
    });
</script>

I each jobcell is click-able and I previously had it to where clicking anyone would submit the form. The problem is that it would only send the information for the hidden information for the last jobcell in the table. Now with my current code, it only allows the user to click the first cell and it does submit. How accomplish submitting the hidden data in the jobcell that is clicked when I have many forms?

  • 写回答

2条回答 默认 最新

  • dongzhimeng2464 2013-08-01 16:17
    关注

    There should only ever be one of each ID on the page. You have you have lots of forms all with the same ID it may well only submit the last. Change id to class, there can be any elements on the same page with the same class.

    At a guess something like this. But without seeing your actual HTML output this could be wrong.

    <script>
        $(document).ready(function()
        {
            $("#jobCell").click(function()
            {
                $(this).children('form').submit();
                //$('.scheduleForm').submit();
            });
        });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)