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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:10:12+00:00 2026-06-01T05:10:12+00:00

I need to take some actions which involve updating a database table when a

  • 0

I need to take some actions which involve updating a database table when a user clicks on the form submit button. I want this action to complete before I now submit the form but it doesn’t work yet. Here is the codes

// On form submission
$("#profile").submit(function() {
    submitForm(function(result) {
        return result;
    });
});

function submitForm(callback) {
    var dept;
    if (IsEmpty($("input[name=dept_id1]").val())) {
        dept = $("select[name=dept_id]").val();
        $.post("funcs.php", {'dept':dept, op:'select'}, function(d) {
            callback(true);
        });
    } else {
        dept = $("input[name=dept_id1]").val();
        $.post("funcs.php", {'dept':dept}, function(d) {
            callback(true);
        });
    }
}

If I prevent the form from submitting, the action will complete successfully but I’ll have to manually go to the result page to see the changes. If I allow the form to submit, the changes won’t take effect.

The codes I pasted here allows the form to submit after the ajax function, but it doesn’t make any changes on the server side.
Thanks for any help.

  • 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-01T05:10:14+00:00Added an answer on June 1, 2026 at 5:10 am

    I’d recommend using a button rather than submit button in your form in this situation. If you’re currently using, for example:

    <form id="profile">    
    Some form fields
    <input type="submit" value="Submit" />
    </form>
    

    Then consider instead doing:

    <form id="profile">
    Some form fields
    <input type="button" onclick="submitForm(submitCallback);" />
    </form>
    

    This would prevent the form from automatically submitting when you click the button. You could actually submit the form in the callback function, for example:

    function submitCallback() {
        $('#profile').submit();
    }
    

    Or something along those lines. Code not tested, but it should be something along these lines.

    Edit: After doing that, you’d want to drop the eventhandler in your original code for $(‘#profile’).submit …otherwise you’d be running that ajax stuff twice.

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

Sidebar

Related Questions

I want to create a form in which i have some textfields and a
i need to take some row. They came from sql TARIH (sql column) is
I need to add functionality to my J2EE-based wep application: 1) Take some page,
I need some help adding conditions to a linq query. Take this small example
I am getting a little confused and need some help please. Take these two
I need to take some action based on the return value of a background
Need to take a SELECT drop down list options and find if any of
I need to take a web page and extract the address information from the
I need to take a paragraph of text and extract from it a list
I need to take a BufferedImage and convert it to YCbCr format so that

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.