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 820127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:25:34+00:00 2026-05-15T02:25:34+00:00

Hey guys I have a system where there is one form for each friend

  • 0

Hey guys I have a system where there is one form for each friend you have and I used to have an ajax post function for each form, but I want to save code and was wondering if it was possible to get multiple forms to work with just one post function. If anyone has any advice on how to achieve this I would appreciate it. For example

<div id="message">
     <form id='submit' class='message-form' method='POST' > 
      <input type='hidden' id='to' value='friend1' maxlength='255' >   
      Subject<br><input type='text'  id='subject' maxlength='50'><br>
       Message<br><textarea id='message2' cols='50' rows='15'></textarea>
       <input type='submit' id='submitmessage' class='responsebutton' value='Send'> 
    </form>
</div>


$(document).ready(function(){
$(".message-form").submit(function() {
 $("#submitmessage").attr({ disabled:true, value:\"Sending...\" });

var to    = $('#to').attr('value');
var subject    = $('#subject').attr('value');
var message    = $('#message2').attr('value');

$.ajax({
type: "POST",
url: "messageprocess.php",
data: 'to='+ to + '&subject=' + subject + '&message=' + message,
success: function(response) {
if(response == "OK") {
$('.message-form').html("<div id='message'></div>");
$('#message').html("<h2>Email has been sent!</h2>")
        .append("<p>Please wait...</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append(\"<img id='checkmark' src='images/check.png' />\");
        });
  • 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-05-15T02:25:34+00:00Added an answer on May 15, 2026 at 2:25 am

    Easily done, e.g.:

    <div class="message">
         <form class='message-form' method='POST' > 
          <input type='hidden' class='to' value='friend1' maxlength='255' >   
          Subject<br><input type='text'  class='subject' maxlength='50'><br>
          Message<br><textarea class='message' cols='50' rows='15'></textarea>
          <div class="result"></div>
        </form>
         <form class='message-form' method='POST' > 
          <input type='hidden' class='to' value='friend2' maxlength='255' >   
          Subject<br><input type='text'  class='subject' maxlength='50'><br>
          Message<br><textarea class='message' cols='50' rows='15'></textarea>
         <div class="result"></div>
         </form>
        <div class="result"></div>
        <button>Send</button>
    </div>
    
    $("button").click(function() {
        $("form.message-form").each(function() {
            var to = $(this).find(".to").val();
            var subject = $(this).find(".subject").val();
            var message = $(this).find(".message").val();
            doPost(to, subject, message);
        });
        return false;
    });
    
    function doPost(to, subject, message ) {
        $.ajax({
            type: "POST",
            url: "messageprocess.php",
            data: 'to='+ to + '&subject=' + subject + '&message=' + message,
            success: function(response) {
                if(response == "OK") {
                        $(this).find(".result").append("<img class='checkmark' src='images/check.png' />");
                }    
            }
        });
    }​
    

    Make sure that your message divs, forms and form elements have unique IDs (or none, if they aren’t necessary). You would be better off giving them a class identifier or such, as in the above example. You will also need to tweak the behaviour of doPost such that it correctly addresses elements based on your new markup structure. The above example has not been tested – my intention here is to give you an idea of what needs to happen rather than to provide a full working solution.

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

Sidebar

Related Questions

hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey guys I have setup Nivo slider to my specification, but what I want
hey guys i have got this far with a chat system but now i
Hey guys I have a form with one input box, when I submit the
Hey guys, I have a weird problem. I have an update system that refreshes
Hey guys I have one more question lol. I am using a script that
Hey guys I have an assigned array from mysql results and I simply want
Hey guys I have a query that currently finds the latest comment for each
Hey guys I have what should be a simple question, but I am new
Hey guys I have enabled APC on my VPS but now I can't access

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.