[SOLVED] Update hidden field value with list box elements
Posted: Tue Apr 20, 2004 2:15 pm
This may have been asked before, but I couldn't find it. I have a select list box that I need to all of the elements (in order) into php.
Basically, I have a list box that gets populated from MYSQL, then the user re-orders the list using javascript, and now I want to put the order back into another table for access later. Does anyone have any idea on how to do this? I'm kind of clueless, thanks.
Here is my code so far, and it doesn't work:
It only shows the selected item.
Basically, I have a list box that gets populated from MYSQL, then the user re-orders the list using javascript, and now I want to put the order back into another table for access later. Does anyone have any idea on how to do this? I'm kind of clueless, thanks.
Here is my code so far, and it doesn't work:
Code: Select all
<?php
<? include "db_connect.php"; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Rank Select</title>
<style type="text/css">
<!--
body, td {
background: window;
color: windowtext;
font: icon;
}
select {
background: window;
color: windowtext;
font: icon;
}
input {
background: buttonface;
color: buttontext;
font: icon;
}
small {
color: graytext;
}
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
function moveOption(selectObj, direction)
{
if(selectObj.selectedIndex != -1)
{
if(direction < 0)
{
for(i = 0; i < selectObj.options.length; i++)
{
swapValue = (i == 0 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].value;
swapText = (i == 0 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].text;
if(selectObj.options[i].selected && swapValue != null && swapText != null)
{
thisValue = selectObj.options[i].value;
thisText = selectObj.options[i].text;
selectObj.options[i].value = swapValue;
selectObj.options[i].text = swapText;
selectObj.options[i + direction].value = thisValue;
selectObj.options[i + direction].text = thisText;
selectObj.options[i].selected = false;
selectObj.options[i + direction].selected = true;
}
}
}
else
{
for(i = selectObj.options.length - 1; i >= 0; i--)
{
swapValue = (i == selectObj.options.length - 1 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].value;
swapText = (i == selectObj.options.length - 1 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].text;
if(selectObj.options[i].selected && swapValue != null && swapText != null)
{
thisValue = selectObj.options[i].value;
thisText = selectObj.options[i].text;
selectObj.options[i].value = swapValue;
selectObj.options[i].text = swapText;
selectObj.options[i + direction].value = thisValue;
selectObj.options[i + direction].text = thisText;
selectObj.options[i].selected = false;
selectObj.options[i + direction].selected = true;
}
}
}
}
this.form.teams.value = '';
for(i = 0; i < selectObj.options.length; i++)
{
teamOrder += selectObj.options[i].value + ',';
}
this.form.teams.value = teamOrder;
}
function selectAll(selectObj)
{
for(i = 0; i < selectObj.options.length; i++)
{
selectObj.options[i].selected = true;
}
return false;
}
// -->
</script>
</head>
<body>
<?
print_r($_POST['id_list']);
print_r($_POST['teams']);
?>
<form method="POST" action="draft.php">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="2">
<select name="id_list[]" id="id_list" size="17" multiple style="width: 120px" scrolling="no">
<?
$query = mysql_query("SELECT TeamID, TeamName FROM Teams ORDER BY TeamName");
while ($result = mysql_fetch_array($query)) {
echo "<option value="$result[0]">$result[1]</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td width="45"><input type="button" onClick="moveOption(this.form.id_list, -1)" value="Up" title="Move Up" style="width: 45px; height: 25px; font-family: webdings; font-size: 10px"></td>
<td width="45"><input type="button" onClick="moveOption(this.form.id_list, 1)" value="Down" title="Move Down" style="width: 45px; height: 25px; font-family: webdings; font-size: 10px"></td>
</tr>
<tr>
<input type="hidden" value="" name="teams" id="teams">
<td colspan="2"><input type="submit" value="Save" style="width: 90px"></td>
</tr>
</table>
</form>
</body>
</html>
?>