javascript - form submit does not work after moving div using Jquery -


i have div in have placed textarea submit button. need put textarea under each post let user post comment.

here shape of textarea

<div id="textarea_wrap">    <div id="textarea_12" class="txtarea">    <form name="post_comment" action="reply.php" method="post">     <input type="hidden" name="post_title" value="post title" />    <input type="hidden" name="post_id" value="12455" />    <textarea class="textarea" id="txt_12"></textarea>    <input type="submit" class="button" value="submit comment />    </form>    </div> </div> 

when innerhtml of div textarea_wrap , move other div using jquery, stops working.

for example

  var txtarea = $("#textarea_wrap").html();   $("#comment_10").html(txtarea); 

it moves textarea_wrap div's inner html #comment_10 div , when view source after moving div using jquery looks this

<div id="comment_10">    <div id="textarea_12" class="txtarea">    <form name="post_comment" action="reply.php" method="post">     <input type="hidden" name="post_title" value="post title" />    <input type="hidden" name="post_id" value="12455" />    <textarea class="textarea" id="txt_12"></textarea>    <input type="submit" class="button" value="submit comment />    </form>    </div> </div> 

but not work, when click on 'submit comment' button, nothing happens. if use code without moving through jquery, works fine. can't understand why not working after moving through jquery.

given form have cloned has same name before, creates error in dom when try submit form.

suggestion: change form name every time clone it.

solution(jquery):

from

var txtarea = $("#textarea_wrap").html(); $("#comment_10").html(txtarea); 

to

var txtarea = $("#textarea_wrap").html(); $("#comment_10").html(txtarea).find('form').attr('name','post_comment'+(math.floor(math.random()*10000))); 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -