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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:53:37+00:00 2026-05-22T23:53:37+00:00

I am new to programming and its my first time to learn AJAX with

  • 0

I am new to programming and its my first time to learn AJAX with PHP.
I got a working sample code from internet and studying it but there are some codes that I don’t understand and I am really frustrated.

In the index.php, I am so confused about the code xmlhttp.open("GET","gethint.php?q="+str,true);. I dont know what the q stands for. As far as I understand, q should stand for an html element with a name q. For example I have <input type="text" name="q" /> then I know that I have a textbox name q. But in this example I can’t find any element that has a name q. Pls help…

index.php

<html>
 <head>
  <script type="text/javascript">
   function showHint(str)
   {
    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();
  }
 </script>
</head>
<body>

<p><b>Start typing a name in the input field below:</b></p>
<form> 
 First name: <input type="text" onkeyup="showHint(this.value)" size="20" />
</form>
<p>Suggestions: <span id="txtHint"></span></p>

</body>
</html>

gethint.php

<?php
 // Fill up array with names
 $a[]="Anna";
 $a[]="Brittany";
 $a[]="Cinderella";
 $a[]="Diana";
 $a[]="Eva";
 $a[]="Fiona";
 $a[]="Gunda";
 $a[]="Hege";
 $a[]="Inga";
 $a[]="Johanna";
 $a[]="Kitty";
 $a[]="Linda";
 $a[]="Nina";
 $a[]="Ophelia";
 $a[]="Petunia";
 $a[]="Amanda";
 $a[]="Raquel";
 $a[]="Cindy";
 $a[]="Doris";
 $a[]="Eve";
 $a[]="Evita";
 $a[]="Sunniva";
 $a[]="Tove";
 $a[]="Unni";
 $a[]="Violet";
 $a[]="Liza";
 $a[]="Elizabeth";
 $a[]="Ellen";
 $a[]="Wenche";
 $a[]="Vicky";

 //get the q parameter from URL
 $q=$_GET["q"];

 //lookup all hints from array if length of q>0
 if (strlen($q) > 0)
 {
  $hint="";
  for($i=0; $i<count($a); $i++)
  {
   if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
  {
    if ($hint=="")
    {
     $hint=$a[$i];
    }
    else
    {
     $hint=$hint." , ".$a[$i];
    }
   }
  }
 }

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
 {
  $response="no suggestion";
 }
 else
 {
  $response=$hint;
 }

 //output the response
echo $response;
?>
  • 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-05-22T23:53:38+00:00Added an answer on May 22, 2026 at 11:53 pm

    In your example, q is a parameter that is passed to gethint.php with the value contained in the variable str.

    The variable gets its value from the “First name” input element, whenever a key is pressed and released (the onkeyup event).

    The value of q is then accessed in the PHP file by the line $q=$_GET["q"];.

    You can name the parameters passed to the PHP page however you like, they don’t need to correspond to HTML elements.

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

Sidebar

Related Questions

I am trying to learn my first programming language. Unfortunately I picked the Iphone
i'm fairly new to programming and still have no idea why its happening or
I am new to PHP but not programming in general. I want to store
I want to learn a new programming language. I have in mind stuff like
I am new to programming.I have seen this code.returning a derived class object to
i been thinking of a new programming language. Before trying to implement it i
Im new to programming and I dont know very much about but I'm making
I'm fairly new at programming, but I've wondered how shell text editors such as
I am new to programming, and am wondering if there is a correct way
I'm quite new to programming, and I was wondering if there is a good

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.