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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:41:26+00:00 2026-05-23T16:41:26+00:00

This is a follow up of another question I asked last night. My problem

  • 0

This is a follow up of another question I asked last night. My problem now is not that the script doesn’t works, but that I’m getting some very strange repeat of an HTML input element when my xmlhttprequest object returns the response text. Here’s the code:

<!DOCTYPE HTML>

<?php

    if(!empty($_GET['uName']))
    {
        $r = mysql_connect("localhost", "root", "pass") or die("Couldn't connect to db");
        mysql_select_db("db", $r) or die ("Couldn't select db");
        $q = mysql_query("select * from users where uName = '{$_GET['uName']}'") or die("Couldn't query table");
        $data = mysql_fetch_assoc($q);
        mysql_close($r);
    }

?>

<html>

<head>

</head>

<body>

<form>

    <input type="text" name="fUName" onchange="ShowUser(fUName.value);" value="name" style="width:125px;">

</form>

<div id="display"><?php print "ID = {$data['id']}"; ?></div>

</body>

</html>

<script type='text/javascript'>

function ShowUser(name)
{
    if(name.length == 0)
    {
        document.getElementById("display").innerHTML = "Please enter a username to check";
        return;
    }
    if(window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    else
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function()
    {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            document.getElementById("display").innerHTML = xmlhttp.responseText;
        }
    };

    xmlhttp.open("GET", "index.php?uName=" + name, true);
    xmlhttp.send();

}

</script>

Here’s the strange problem:

enter image description here

There should only be one input field, and is orginally, however when I enter text into it and it loses focus, the JS is triggered and also prints out another input field.

Please ignore the bad practice of PHP, JS and HTML/CSS in one script, this was supposed to be a quick test that has turned for the worse 🙂

I’m baffled!

Thanks for any help.

  • 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-23T16:41:26+00:00Added an answer on May 23, 2026 at 4:41 pm

    The problem lies in the fact that all of your code is in one page. Consider this: you load up index.php. After it’s all displaying then you call this same page again (for your AJAX request) so you’re essentially saying “Hey, I want you to try and load this page again,” hence why you’re ending up with duplicate fields.

    Try separating out your files in to something like index.php and getuser.php or something of the sort.

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

Sidebar

Related Questions

This is a follow up question from another post but that post was answered.
This is a follow-up to another question I asked, but with more precise information.
This is a follow-up to another question I asked earlier today. I am creating
This is a more specific question to follow up on [another question that I
FYI: This is a follow up to another question: Position element absolutely, but to
This is a follow-up to another question I asked: Android -- get MEID from
This is a follow up to a question that was asked yesterday. I have
This is a follow up to another question of mine. The solution I found
This is a continuation question from a previous question I have asked I now
This is a follow on from another question i made I have this query

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.