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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:34:19+00:00 2026-06-05T20:34:19+00:00

I am modifying the tutorial found here: http://www.w3schools.com/ajax/ajax_aspphp.asp so that the library of autocomplete

  • 0

I am modifying the tutorial found here: http://www.w3schools.com/ajax/ajax_aspphp.asp
so that the library of autocomplete names are stored on a database. I added a button which allows the user to add a name to the database if it is not already in the database. When I click the button, the method fires, however the php script designated in the addName() method does not execute. This is strange because the script defined in the showHint() method does execute. Here is my javascript (this is all that is necessary to be shown). I have omitted the scripts:

    <!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
        function showHint(str)
        {
            var xmlhttp;
            if (str.length==0)
            {
                document.getElementById("txtHint").innerHTML="";
                return;
            }
            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("txtHint").innerHTML=xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","gethint.php?q="+str,true);
            xmlhttp.send();
        }

        function addName(str){
            var xmlhttp;
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.open("GET","addName.php?q="+str,true);
            xmlhttp.send();
        }
    </script>
</head>
<body>

<h3>Start typing a name in the input field below:</h3>
<form action="">
    First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>Suggestions: <span id="txtHint"></span></p>
<button type="button" onclick="addName(document.getElementById('txt1').value)">Add Name</button>

</body>
</html>
  • 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-05T20:34:21+00:00Added an answer on June 5, 2026 at 8:34 pm

    Like this:

      function getXhr() {
          var xmlhttp;
          if (window.XMLHttpRequest) {// code for IE7+, FF, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();
          }
          else { // code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
          return xmlhttp;
      }
    
      function showHint(str) {
          var xmlhttp;
          if (str.length==0) {
              document.getElementById("txtHint").innerHTML="";
              return;
          }
          xmlhttp = getXhr();
          xmlhttp.onreadystatechange= function() {
              if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
              }
          };
          xmlhttp.open("GET","gethint.php?q="+str,true);
          xmlhttp.send();
      }
    
      function addName(str) {
          var xmlhttp = getXhr();
          xmlhttp.onreadystatechange= function() {
             ...your logic here...
          };
          xmlhttp.open("GET","addName.php?q="+str, true);
          xmlhttp.send();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the code block below (source: http://www.asp.net/learn/mvc/tutorial-31-cs.aspx )... I receive this error: Using the
I am trying to implement reset password functionality using the tutorial at http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic/ and
So I've been modifying the notepad tutorial code: http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html . Basically what I want
I am modifying a css3 nav that i found in a tutorial and I
I've got a button posted here: http://buttontest.raptorshop.com/ But for some reason, it isn't entirely
I was reading Crockford's tutorial http://javascript.crockford.com/private.html . private variables are implemented by function inside
I'm modifying a SDK tutorial that pulled from a very basic SQLite DB and
I am modifying a tutorial I found on how to create a TCP Chat
Modifying CKEditor 3.6.2 is not easy, but I tried hard . One problem that
I'm modifying an existing application in C++ that uses GLUT (so I can't get

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.