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

  • Home
  • SEARCH
  • 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 7177509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:43:44+00:00 2026-05-28T16:43:44+00:00

I have a simple form right now: <form action='<? echo $PHP_SELF;?>’ method=’POST’> Username:<input type=’text’

  • 0

I have a simple form right now:

<form action='<? echo $PHP_SELF;?>' method='POST'>
Username:<input type='text' name='username'><br>
Email:<input type='text' name='email'><br>
Posts:<input type='text' name='posts'><br>
Joindate<input type='text' name='join'><br>
<input type="submit" value="Submit" />

What I need is, when the user fills his username and does one of the following:
1.presses tab
2.Presses enter
3.clicks on a fetch button(fetch button does not exist now,i would like to know how to create it using javascript or anything else that suits my criteria)

Once he does any of the above it should automatically generate the remaining fields from the database.
The query would look like this:
$qry=mysql_query(“SELECT * from user where username =$_POST['username']“);
$row=mysql_fetch_assoc(‘$qry);
echo $row[‘posts] and so on..

After it is autogenerated he can edit the fields and submit to update the database fields.

Here is my updated code:

<head>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>

</head>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="POST">
<fieldset>
<legend>Form</legend>
<label for="username">Username: </label>

<input type="text" id="username"  name="username" /> 
<button onclick="myrequest()">fetch</button>
<label for="posts">Posts: </label>
<input type="text" id="posts" name="posts"  size="20"/>
<label for="joindate">Joindate: </label>
<input type="text" id="joindate" name="joindate"  size="20"/>



<p><input type="submit" name="submitBtn" value="Submit" /></p>

</fieldset>
</form>
<script type="javascript/text>
function myrequest() {
var name = $('.username').val();
$.ajax({
  method: "GET",
  url: "http://url.com/test/autofill.php",
  dataType: 'json',
  data: {
    username: username
  }).success(function( responseObject ) {
    // assuming you have an array of stuff like name, id, email, etc.
    // now i populate another field from the ajax response
    $('.posts').val( responseObject.posts );
  });

} 
And then in the autofill.php

    //connect to database
    $name = $_GET['username'];
    $return = mysql_query("SELECT * FROM user WHERE username = '$name' LIMIT 1");
    $rows = mysql_fetch_array($return);
    $formattedData = json_encode($rows);
    print $formattedData;
  • 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-28T16:43:45+00:00Added an answer on May 28, 2026 at 4:43 pm

    Make a php endpoint (basically a url in which you can call your special php function, which returns only the data you want) that returns a json_encode’d array with all of the other fields’ info.

    Call that function via ajax when the first field either loses focus or changes (or a button is pressed), depending on your preference.

    Then using javascript, use what you’ve gotten back from the ajax response to populate the other fields.

    autoFill.php

    $name = $_GET['name'];
    $return = mysql_query("SELECT * FROM someTable WHERE username = '$name' LIMIT 1");
    $rows = mysql_fetch_array($return);
    $formattedData = json_encode($rows);
    print $formattedData;
    

    Javascript (using jquery)
    //gets the val from the first field

    $(document).ready(function() {
        function myrequest(e) {
            var name = $('.username').val();
            $.ajax({
                method: "GET",
                url: "/echo/json/", /* online, change this to your real url */
                data: {
                    username: name
                },
                success: function( responseObject ) {
                    alert('success');
                    $('#posts').val( 'posts' );
                    $('#joindate').val('testing join date');
                    /*
                    once you've gotten your ajax to work, then go through and replace these dummy vals with responseObject.whatever
                    */
                },
                failure: function() {
                    alert('fail');
                }
            });
        }
    
        $('#fetchFields').click(function(e) {
            e.preventDefault();
            myrequest();
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
Right now I have simple form with a single input. I'm trying to use
I have this html right now: <h1><span class = 'highlight'><input type='image' class='removeall' src='remove.png'> <input
I have a simple form with some plain html input like bellow using ASP.NET
I have a simple form that looks like so <% remote_form_for post, :url =>
Have a simple form (only extract fields here) but for some reason the JQserilization
I have a simple form on a view page, implemented as a user control,
I have a simple form on a page and I want to auto submit
I have a simple form in python + pylons that submits to a controller.

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.