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 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题