Page 1 of 1

retrieving value of <select> list

Posted: Mon Jan 26, 2004 10:05 pm
by Smeagol
Hi guys.

I'm having a little problem retrieving the current value of a <select> list. The function below renders the form and the user must choose a client from a client list and view all users currently associated with the client.

===============================================
function viewClientGroup() {

$mysqlUserName = "ara";
$mysqlPass = "gee32k4a";
$db = "GV_DB";
$table = "clients";
global $actionItem;

mysql_select_db($db);
$sql="SELECT client_name FROM ".$table." order by client_name";
$users = mysql_query($sql);
$actionItem = "<form method=\"post\" name=\"viewClientForm\" action=\"userAdmin.php?action=viewUser&clientGroup=";
?>
<script language="JavaScript">
this.viewClientForm.viewClientGroups.value;
</script>
<?
$actionItem .= "\">\n";
$actionItem .= "<p class=bodyTextWhite>Select a client group you wish to view users from.</p>";
$actionItem .= "<select name=\"viewClientGroups\" onChange=\"doStuff()\">\n";

while ( $user = mysql_fetch_array($users) ) {
$actionItem .= "<option value=\"".$user["client_name"]."\">".$user["client_name"]."</option>\n";
}
$actionItem .= "<option>----------------------------</option>\n";
$actionItem .= "</select>\n";
$actionItem .= "<p></p><input type=\"submit\" name=\"submit\" value=\"View users\" class=\"buttonOff\">";
$actionItem .= "</form>";
}

doStuff javascript function below

function doStuff() {
theUserGroup = document.viewClientForm.viewClientGroups.value;
alert(theUserGroup);
}
===============================================
Now... I need to pass the current selected value of the select list to a URL string (the action url of the form). How can I do this?

$actionItem = "<form method=\"post\" name=\"viewClientForm\" action=\"userAdmin.php?action=viewUser&clientGroup=NEED A VALUE HERE";

Posted: Mon Jan 26, 2004 10:07 pm
by Smeagol
The javascript within this php function doesnt work... that's fine... but you can sorta see what I am getting at... I hope. hehe