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 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用