Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8405865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:56:34+00:00 2026-06-09T22:56:34+00:00

I am submitting a form via a jqery function that’s dynamically created with using

  • 0

I am submitting a form via a jqery function that’s dynamically created with using php and a while loop. The form gets submitted correctly the first time and I generate html and display it using .html(response). I replicate the code so that the function will work again, however it doesn’t. When I submit the form a second time (without a page refresh), the form sends me to the action attribute.

Is this a limitation of jquery?

My code:

<script type="text/javascript">
$(document).ready(function() {

$("#submit<? echo"$counter$counter";?>").click(function() {

var action = $("#commentform<? echo "$counter$counter";?>").attr('action');
var form_data = {
comment: $("#comment<? echo "$counter$counter";?>").val(),
type: $("#commenttype<? echo "$counter$counter";?>").val(),
typeid: $("#commenttypeid<? echo "$counter$counter";?>").val(),
counter: $("#commentcounter<? echo "$counter$counter";?>").val(),
is_ajax: 1
};

$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response)
{
$("#commentarea<? echo"$counter$counter";?>").html(response);
}
});
return false;
});
});
</script>

My form that’s on the same page as the script I am running:

<div class="postcommentscomment" style="size:10px; font-family:Verdana, Geneva, sans-serif;">
<form action="php/comment.php" id="commentform<? echo "$counter$counter";?>" method="post" name="comment" target="_self">
<textarea id="comment<? echo "$counter$counter";?>" style="width:162px; height:24px; color:#827e78; font-size:10px;">comment here</textarea>
<div style="float:right; position:relative; margin-top:5px;">
<input id="commenttype<? echo "$counter$counter";?>" type="hidden" value="<? echo $type;?>" />
<input id="commenttypeid<? echo "$counter$counter";?>" type="hidden" value="<? echo $id;?>" />
<input id="commentcounter<? echo "$counter$counter";?>" type="hidden" value="<? echo "$counter$counter";?>" />
<input id="submit<? echo"$counter$counter";?>" type="button" value="comment"/>
</div>
</form>
</div>

My form on the html(response) page via the action attribute

<div class="postcommentscomment" style="size:10px; font-family:Verdana, Geneva, sans-serif;">
<form action="php/comment.php" id="commentform<? echo "$counter";?>" method="post" name="comment" target="_self">
<textarea id="comment<? echo "$counter";?>" style="width:162px; height:24px; color:#827e78; font-size:10px;">comment here</textarea>
<div style="float:right; position:relative; margin-top:5px;">
<input id="commenttype<? echo "$counter";?>" type="hidden" value="<? echo $type;?>" />
<input id="commenttypeid<? echo "$counter";?>" type="hidden" value="<? echo $id;?>" />
<input id="commentcounter<? echo "$counter";?>" type="hidden" value="<? echo "$counter";?>" />
<input id="submit<? echo"$counter";?>" type="button" value="comment"/>
</div>
</form>
</div>

NOTE: The counter php variable is set such that $counter on the html(response) page produces an equivalent result as $counter$counter on the original page.

So, I submit a comment, the comment gets inserted into the database, then a query is run, a form is reproduced and displayed on the original page via html(response). When I then try to submit a new comment I get redirected to the action page. I stopped that by changing “submit” to “button”, but that doesn’t give me the result I want — which is to be able to submit the form again.

Not sure if this is a jquery limitation or a problem with my code.

Also, the comments are on a page that has may different posts. So multiple comment forms. If there is a better way to execute a ajax refresh of the comments for a specific post, I am open to changing code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:56:35+00:00Added an answer on June 9, 2026 at 10:56 pm

    Your code is executed on document ready, if you would insert that code a second time, document ready won’t fire again.

    You could attach your function to the submit handler of the form…

    $('.postcommentscomment form').submit(function() {
    
        var form_data = $(this).serialize();
    
        //your ajax call
    
    });
    

    You should be able to execute this piece of code every time you insert a form, the serialize function is a more easy option compared to getting all input values by id and saves you from all those silly inline php counter echo’s.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently submitting a simple PHP form via JavaScript using document.add_driver.submit(); This method
I faced the following issue while I submitting my form using jQuery FORM and
I'm having trouble submitting some hidden form data via post from the following function:
Don't know why this is happening, but after submitting a form via JS (using
I am submitting form via javascript by using 'document.FormName.submit()' . But this is giving
so i have form that I am submitting via jQuery form's ajaxSubmit it was
I'm submitting a form via HTML into a POST PHP page, which is then
I am submitting a single text area form via :remote => true. It works
Upon submitting this form on my site. It send me to a page that
I'm submitting a form using an ajax request (POST method), and checking the HTTP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.