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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:11:49+00:00 2026-06-11T23:11:49+00:00

I’m developing a form that submits several user inputs to a database via post

  • 0

I’m developing a form that submits several user inputs to a database via post and handled by php. In order to do so, I’m using ajax (I know jquery is sometimes easier, but I’d prefer to get a grasp on ajax first).

However, it is not working properly – namely that it doesn’t work at all. I know for a fact that the php file works fine when the form isn’t passed through ajax.

Here’s what I have right now – the form itself:

<table border="0" cellpadding="2" cellspacing="5">
                <th colspan="2" align="center">Check Out</th>
                <form name="checkOut" method="post" onSubmit="return(validate(this))" action=""> 
                    <tr><td>Territory Number</td><td><input type="text" name="numberOut" tabindex="1" maxlength="3" size="3" /></td>
                    </tr><tr><td>First Name of Publisher</td><td><input type="text" onKeyUp="showHint(this.value)" name="fName" tabindex="2" maxlength="15"/></td>
                    </tr><tr><td>Last Name of Publisher</td><td><input type="text" onKeyUp="showHint_l(this.value)" name="lName" tabindex="3" maxlength="15" /></td>
                    </tr><tr><td><input type ="checkbox" name="specialC" tabindex="4" value="Yes"/> Special Campaign</td>
                    </tr><tr><td><input type="button" onClick="clearForm()" value="Reset" /></td><td><input type="submit" value="Check Out" /></td>
                </form>
                <p>Suggestions: <span id="txtHint"></span></p>
            </table>

The javascript/ajax handler function:

<script type="text/javascript">
        function validate(form)
        {
            fail = validateTerrNum(document.checkOut.numberOut.value);
            fail += validateFirstName(document.checkOut.fName.value);
            fail += validateLastName(document.checkOut.lName.value);
            if (fail == "")
            {
                //Begin preparing values for submission to server
                var params = "numberOut="+document.getElementsByName("numberOut")[0].value;
                    params+="?fName="+document.getElementsByName("fName")[0].value;
                    params+="?lName="+document.getElementsByName("lName")[0].value;
                var isSc = document.getelementsByName("specialC")[0].checked;
                if(isSc)
                {
                    params+="?specialC=Yes";
                }

                //Send those values to the server
                checkOut(params);
                return true;            
            }           
            else 
            {
                alert(fail);
                return false;
            }
        }
    </script>

And finally the ajax function via post:

function checkOut(params)
{
var urlString = params;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("test").innerHTML=xmlhttp.responseText; 
    }
}
//Setup for post submission 
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.open("POST","checkOut.php",true);
xmlhttp.send(urlString);
}

My suspicion is that I’m not submitting the post request correctly. I’ve had other ajax functions work with this form correctly, but it was through get – and I do want to use post because it is changing data in the database.

If anyone has some insight on this, it would be appreciated.

Edit: New Form with general button:

<table border="0" cellpadding="2" cellspacing="5">
                <th colspan="2" align="center">Check Out</th>
                <form name="checkOut" method="post" action=""> 
                    <tr><td>Territory Number</td><td><input type="text" name="numberOut" tabindex="1" maxlength="3" size="3" /></td>
                    </tr><tr><td>First Name of Publisher</td><td><input type="text" onKeyUp="showHint(this.value)" name="fName" tabindex="2" maxlength="15"/></td>
                    </tr><tr><td>Last Name of Publisher</td><td><input type="text" onKeyUp="showHint_l(this.value)" name="lName" tabindex="3" maxlength="15" /></td>
                    </tr><tr><td><input type ="checkbox" name="specialC" tabindex="4" value="Yes"/> Special Campaign</td>
                    </tr><tr><td><input type="button" onClick="clearForm()" value="Reset" /></td><td><input type="button" onClick="return(validate(this))" value="Check Out"/></td>
                </form>
                <p>Suggestions: <span id="txtHint"></span></p>
            </table>
  • 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-11T23:11:51+00:00Added an answer on June 11, 2026 at 11:11 pm

    You have to cancel the form submit if you’re posting the data via ajax, otherwise the form will submit and that may cancel your ajax request.

    Also you have to call setRequestHeader after you call open

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.