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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:16:09+00:00 2026-05-31T22:16:09+00:00

I tried the following code from w3schools. When I enter letters in a input

  • 0

I tried the following code from w3schools. When I enter letters in a input txt box, suggestions should get displayed accordingly. However, nothing is getting displayed as suggestion. I’m not able to get the txt value with serialize.
In gethint.php, since it is a post request, i changed the original $q=$_GET[“q”]; to $q=$_POST[“q”].
Can someone tell me on what i’m doing wrong? thank you.

post_example.html

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("input").keyup(function(){
    // txt=$("input").val();
    txt=$("input").serialize();
    $.post("gethint.php",txt,function(result){
      $("span").html(result);
    });
  });
});
</script>
</head>
<body>
<p>Start typing a name in the input field below:</p>
First name:

<input type="text" >
<p>Suggestions: <span></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=$_POST["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-31T22:16:10+00:00Added an answer on May 31, 2026 at 10:16 pm

    i think you are missed, the q in your line

    $.post("gethint.php",txt,function(result){
    

    should be

    $.post("gethint.php", {q: txt},function(result){
    

    or if you are using serialize then use the name of the input box like

    <input type="text" name="q" >
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried the following code to get an alert upon closing a browser window:
I tried the following code. Although I don't get any errors, it did not
I tried to run the following code from http://docs.python.org/library/mmap.html import mmap # write a
In my opinion, the following code (from some C++ question) should lead to UB,
Following example code from the libpcap documentation yields the following code which should report
I am a newbie to PHP development. I tried following code sample from PHP5
I tried the following example code from the tutorial that came along wxPython2.8 Docs
I tried following some of the code from here and here , but I
I tried the following code in LINQPad and got the results given below: List<string>
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,

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.