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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:09:51+00:00 2026-06-05T11:09:51+00:00

i am trying to write program,which ask user to enter some letters or strings

  • 0

i am trying to write program,which ask user to enter some letters or strings and by this string,list these cities ,for which this string or letter is prefix
i have following html file

<html>
<head>
<script>
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","USA.php="+str,true);
xmlhttp.send();
}
</script>

</head>
<body>
<h3>entering  any city names which you like  </h3>
<form action="USA.php" method="post" >
CITY :<input type="text" name="city" value=" " onkeyup="showHint(this.value)"></br>
<input type="submit" value="Submit"/>
</form>

<p>Suggestions: <span id="txtHint"></span></p> 
</body>
</html>

and also USA.php file

<html>
<body>
<?php
$c=$_GET['city'];
$d=strlen($c);

$filename=file("UScities.txt");
$out=" ";
foreach ($filename as $line)
{

if (strtolower($c)==substr($line,0,$d)){
if($out=="")
{
$out=$line;
}
else
{
$out=$out. ' , ' . $line;
}
}
}
echo $out

?>
</body>
</html>

but when i run it in firefox,it gave me following error

Notice: Undefined index: city in C:\xampp\htdocs\united\USA.php on line 4

but i could not understand this error, why is city undefined index?
EDITED:

html code
<html>
<head>
<script>
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", "USA.php?city="+str, true);
xmlhttp.send();
}
</script>

</head>
<body>
<h3>entering  any city names which you like  </h3>
<form action="USA.php" method="post" >
CITY :<input type="text" name="city" value=" " onkeyup="showHint(this.value)"></br>
<input type="submit" value="Submit"/>
</form>

<p>Suggestions: <span id="txtHint"></span></p> 
</body>
</html>

php file

<html>
<body>
<?php
$c=$_POST['city'];
$d=strlen($c);

$filename=file("UScities.txt");
$out=" ";
foreach ($filename as $line)
{

if (strtolower($c)==substr($line,0,$d)){
if($out=="")
{
$out=$line;
}
else
{
$out=$out. ' , ' . $line;
}
}
}
echo $out

?>
</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-05T11:09:52+00:00Added an answer on June 5, 2026 at 11:09 am

    Here try this one:

    xmlhttp.open("GET","USA.php?city="+str,true);
    

    Ok, this is the problem. you request for hint on USA.php and you submit your form also in USA.php. Yet on requesting for list of hint, you used

    xmlhttp.open("GET","USA.php?city="+str,true);

    however you form used post method

    <form action="USA.php" method="post" >

    the problem is on USA.php you used post

    $c=$_POST['city'];

    I recommend you change the ff.

    $c=$_POST['city']; => $c=$_GET['city'];

    <form action="USA.php" method="post" > => <form action="USA.php" method="get" >


    Last edit:
    Change your condition into this my friend. and your all set!

    if (strtolower($c)==strtolower(substr($line,0,$d)))

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

Sidebar

Related Questions

I'm trying to write a program which prompts the user to enter two 3×3
I'm trying to write a program which, at some point, needs to invoke an
i am trying to write a program which inputs two numbers from user as
I am currently trying to write a program which asks the user for a
i am trying to write a scheme program which will take a list of
I was trying to write this basic JavaScript program which changes the background color
I'm trying to write program which will switch tasks. Everything seems to work properly,
I am trying to write a program which will allow two players to play
I am trying to write a program which gets input files and prints included
I am trying to write a program in PHP which I had already written

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.