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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:14:44+00:00 2026-06-02T00:14:44+00:00

I am looking at this script from W3schools.com (Ajax, PHP and Mysql) http://www.w3schools.com/php/php_ajax_database.asp <html>

  • 0

I am looking at this script from W3schools.com (Ajax, PHP and Mysql)
http://www.w3schools.com/php/php_ajax_database.asp

<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  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","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>

This shows a simple select with 4 values.

And this is the PHP script.

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', '*', '*');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ajax_demo", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

Now I understand what it does and how it works, but let’s say that I want to pass 3 more variables to the PHP script, when someone changes the value of the selectbox, how do I do that??

  • 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-02T00:14:46+00:00Added an answer on June 2, 2026 at 12:14 am

    Following on from my comments, here’s an example that takes the values from 2 selects, and submits an ajax call when both are filled in

    // Notice the arguments are gone at the moment
    function showUser() {
        // Retrieve values from the selects
        var u = document.getElementByID('userSelect').value;
        var g = document.getElementByID('groupSelect').value;
    
        if (u=="" || g == "") {
            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","getuser.php?u="+u+"&g="+g,true);
        xmlhttp.send();
    }
    

    And then the basic form

    <form>
        <select name="users" id="userSelect" onchange="showUser()">
            <option value="">Select a person:</option>
            <option value="1">Peter Griffin</option>
            <option value="2">Lois Griffin</option>
            <option value="3">Glenn Quagmire</option>
            <option value="4">Joseph Swanson</option>
        </select>
        <select name="groups" id="groupSelect" onchange="showUser()">
            <option value="">Select a group:</option>
            <option value="a">Aerosmith</option>
            <option value="k">Kiss</option>
            <option value="l">Led Zeppelin</option>
            <option value="m">Metallica</option>
        </select>
    </form>
    

    This is not a fantastic option though, and as mentioned would recommend that you into using a framework such as jQuery ( http://jquery.com/ ) as you will be able to spend more time on the logic rather than ensuring browser compatibility

    However you go about it though, it doesn’t hurt to experiment so just give some things a try and see what happens (so long as you aren’t deleting live data, anyway)

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

Sidebar

Related Questions

Looking at an example on image upload with JQuery here: http://www.zurb.com/playground/ajax_upload Using this example
looking at this example of the jquery ui slider http://jqueryui.com/demos/slider/#steps i want to be
Im looking at this implementation of DCT using cuda: http://www.cse.nd.edu/courses/cse60881/www/source_code/dct8x8/dct8x8_kernel1.cu The part in question
Looking for help setting the output from this vbs script and using it as
I have a website scrolling horizontally using this script: http://tympanus.net/Tutorials/WebsiteScrolling/index.html Sometimes with this build
I currently start a shell script from my Java by code looking like this:
Recently I've been looking at opening a tab using this script: $('.tofour').click(function() { //
Not sure this is possible, but looking to write a script that would return
I was looking at this article from 2005 and wanted to get some thoughts
I am looking for some help. I have found this script that sort of

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.