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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改