Probably a simple solution here, I'm confusing myself. I've got a <select>
that populates via an array from a MySQL database of users. No problem there. I've also got a script that when a certain user is selected, I can via AJAX the user's user_id. My problem, is getting that user ID into a variable $assigned_to, to include in a URL.
I'm sorry the coding is so specific. If requested, I can break it all down into a much more simplified version.
Here's what I've got so far:
<script type="text/javascript">
function showData(str)
{
if (str=="")
{
document.getElementById("showData").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("showData").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getdata.php?assign_to="+str,true);
xmlhttp.send();
}
</script>
//
//This gets the user_id value from the `<select>` when a user selects it.
//
<?php
//
//Here is the function that displays my users:
//
function userlist()
{
echo "<select name=\"assigned_to\" onChange=\"showData(this.value)\">";
echo "<option default value=\"\">Assignee</option>";
$mysqli = new mysqli("xxx", "xxx", "xxx", "xxx");
$userlist = "SELECT * FROM users where user_level = 2";
$result = $mysqli->query($userlist);
while( $row = $result->fetch_assoc() ) {
echo "<option value=\"".$row['user_id']."\">".$row['first_name']." ".$row['last_name']."</option>";
}
echo "</select> ";
}
echo "<p>";
echo userlist();
echo "<a id=\"show\" href=\"index.php?page=overview&location=advance&assignee=\"".$assign_to."\">Assign</a></p>";
?>
<!-- The line below **will** display the correct user_id value when selected -->
<div id="showData">User Id Shows Here</div>
That last URL variable $assign_to is what I want the value from $row['user_id'] when selected to return.
I understand the ideal method of going about all of this is to just post a form to a php page and using _POST to retrieve all these variables. Unfortunately in this circumstance I need the variable in the URL.
Thanks as always.
$_GET["assign_to"]
– Kevin B Feb 20 at 20:19<select>
? – Kevin O'Brien Feb 20 at 20:25