I know I am new but my regular forum couldn't help me.
I am having a bit of trouble in working this out. I have two drop down boxes which the user can choose a selection from either one. Once a selection is made, just under the drop downs a small table will show with the appropriate data. This is so the user can confirm the selection.
After that there are a few other fields to fill in and then the user submits the form and the data is stored in a database. All of that is fine, except I can't get the data in the table from the selection to post as well.
I did find a script online so not too sure what to do about it.
Any help would be greatly appreciated.
This is just a sample of what I want to achieve
index.php
Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<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 name="testform" method='POST' action='mainck.php' onSubmit="return checkdate(this.mydate)">
<p>Person:
<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>
</select>
<div id="txtHint">Person info will be listed here.</div>
<br>
Date:
<input type="text" name="mydate" />
<br>
<input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" />
</p>
</form>
</body>
</html>getuser.php
Code: Select all
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'name', 'pass');
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);
?>Thanks in advance