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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:39:46+00:00 2026-06-13T10:39:46+00:00

New to jquery. How can I have a simple form with a Save button

  • 0

New to jquery. How can I have a simple form with a Save button and a Save-Exit button?

What I have right now does ‘work’ in a way. But when I post then click save-exit. Then go back to /messages. Use the form and click save-exit it posts and stays on the page. But then if I repeat then it will post and exit.

JQUERY

var BASE = 'http://localhost/sym/messages';

$('#xhrSave').submit(function() {

    event.preventDefault();

    $('[name="save_continue"]').click(function() {
        window.location = '#';
    });

    $('[name="save_exit"]').click(function() {
        window.location = BASE;
    });

    var url = $(this).attr('action');
    var data = $(this).serialize();

    $.ajax({
        type: 'post',
        url: url,
        dataType: 'json',
        data: data,
        success: function(data) {

            $('#message_list').append('<div>' + data.message + '<a class="delete" rel="'+ data.id +'" href="#">Delete</a></div>');

        }

    });

    // clear textbox
    $('#form_message').val('');

});

HTML

<form action="<?=URL::to('messages/xhrSave')?>" method="post" id="xhrSave">

<input type="text" name="message" value="" id="form_message" />

<button type="submit" name="save_continue" class="save_form">Save</button>
<button type="submit" name="save_exit" class="save_form">Save-Exit</button>

  • 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-13T10:39:48+00:00Added an answer on June 13, 2026 at 10:39 am

    There are lots of ways of doing this thing , none can be said the best , just putting what way I use in general.

    Change your html to this :

    <input type="text" name="message" value="" id="form_message" />
    
    <button type="submit" name="save_continue" class="save_continue save_form">Save</button>
    <button type="submit" name="save_exit" class="save_exit save_form">Save-Exit</button>
    

    and js:

    function myajaxcall(type){
                         var url = $(this).attr('action');
            var data = $(this).serialize();
    
            $.ajax({
                type: 'post',
                url: url,
                dataType: 'json',
                data: data,
                success: function(data) {
    
                    $('#message_list').append('<div>' + data.message + '<a class="delete" rel="'+ data.id +'" href="#">Delete</a></div>');
                    //one way to redirect
                   if(type=="exit")
                   window.location = "thepageyouwanttogo.php"
    
                }
    
            });
    }
    $('.save_continue').click(function() {
            myajaxcall("continue")
    });
    $('.save_exit').click(function() {
            myajaxcall("exit")
    });
    

    NOTE:I haven’t checked your js in the ajax just copied it for question

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

Sidebar

Related Questions

I'm new to JQuery and was wondering how can I have Changes saved! displayed
I'm kind of new to JQuery and was wondering how can I have the
I new with jquery and I can do simple coding with it. and I
I have a simple form that generates a new photo gallery, sending the title
Hey all, i have made a simple form that mimiks the jQuery GROWL effect
I have made a simple chat script using jquery and AJAX but the huge
I'm fairly new to Jquery, so this might be a simple problem, but is
I have a fairly simple website where users can fill out a form describing
I have a pretty simple HTML form where users can enter in information about
Hi, I have this code and I can't get it to work. I'm new

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.