douhutongvm382381 2016-07-15 10:15
浏览 82
已采纳

许多的第一个表单在点击时提交

Problem: Multiple forms on the same page, but only the first one is being submitted.

Tried the following: Equating the data-ids of submit button and Form inorder to submit the clicked form (No Luck) Dynamic form creation using Javascript.(disbanded that idea after a few tries since it was on a deadline)

Usecase The number of forms depends on the User. If there is just one comment from him, the form submits, while if there are say 4 forms, only the first one will submit.

Javascript:

$(function() {
    $(".submit").click(function() {
        var data_id = $(this).data('id');
        var form_id = $(this.form).data('id');
        if (parseInt(data_id, 10) == parseInt(form_id, 10)) {
            var commentid = document.getElementByID('commentid');
            alert(commentid + formid);
        } else {
            alert("10");
        }
    });
});

PHP code:

if($comment['Comment_Username'] ==$this->getUser()->getName()) 
{$output .='div class="panel" data-class="'.$comment['CommentID'].'">';
$output .='<form class="form" action="" method="post" data-  id="'.$comment['CommentID'].'">';
$output .='<textarea name="edit_text' class="box" rows="2" cols="1">'.$this->getCommentText($comment['Comment_Text']).'</textarea>';
$output .='<input name="commentid" type="hidden" id="commentid" value="'.$comment['CommentID'].'"/>';
$output .='<input type="button' data-id="'.$comment['CommentID'].'" class="submit" value="submit"/>';

Any help would be greatly appreciated. Thanks in advance

  • 写回答

1条回答 默认 最新

  • dongwan5381 2016-07-15 10:17
    关注

    Wrong quote used here

    $output .='<textarea name="edit_text" class="box" rows="2" cols="1">'.$this->getCommentText($comment['Comment_Text']).'</textarea>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭