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

The Archive Base Latest Questions

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

I am having problem with this javascript function. If I want to submit a

  • 0

I am having problem with this javascript function.

If I want to submit a form if I do this below it works:

function submitform()
{
    var QandAO = document.getElementById("QandA");
    QandAO.submit();
}

If I want to add a row into a DB table using AJAX to navigate to the page which INSERTS VALUES, then the code below works:

function submitform()
{
    var fieldvalue = $("#QandA").val();
    $.post("insertQuestion.php", $("#QandA").serialize ,function(data){
        alert("data");
    });
}

So I thought to be able to submit the form and add a row into the database, if I do this code below then it should work but it doesn’t. It submits the form but does not add a row in the database. How can this code be fixed so it submits the form and also add a row in DB? Below is the code

function submitform()
{
    var fieldvalue = $("#QandA").val();
    $.post("insertQuestion.php", $("#QandA").serialize ,function(data){
        alert("data");
    });   
    var QandAO = document.getElementById("QandA");
    QandAO.submit();
}

InsertQuestion.php looks like this below:

<?php
session_start();

$username="xxx";
$password="xxx";
$database="xxx";

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$insertquestion = array();
$insertquestion[] = "' ". mysql_real_escape_string( $_POST['id'] ) . "'";

$questionsql = "INSERT INTO Question (SessionId) 
VALUES (" . implode('), (', $insertquestion) . ")";

mysql_query($questionsql);
mysql_close();
?>
  • 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-01T07:12:49+00:00Added an answer on June 1, 2026 at 7:12 am

    I think the problem is that the second part of your code (the form submit) cuts off the first part before it’s complete. Give the AJAX call a chance to finish by putting the form submit inside the AJAX callback:

    function submitform()
    {
        var fieldvalue = $("#QandA").val();
        $.post("insertQuestion.php", $("#QandA").serialize ,function(data){
            alert("data");
            var QandAO = document.getElementById("QandA");
            QandAO.submit();
        });   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have given below simplified JavaScript problem. var PROJ=(function(){ var tags={}, var lock=true; function
I have the following function: <script type=text/javascript> function changeText(elem){ var oldHTML = document.getElementById(elem).innerHTML; var
I've been having a problem with the javascript innerHTML function when using forms. I've
I'm having real difficulty with this but I'm no javascript expert. All I want
I am having difficulties testing window.setInterval function in my Javascript file. Below is the
I am having this problem : Whenever, some specific button is clicked my javascript
I am having problem getting this piece of code to run. The class is
I'm not a MySQL expert and am having problem with this... So, I have
I'm having this problem, same as ever, but never try to find the right
I'm having this problem and I reached a deadlock, I would try anything I've

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.