Odswiezam.
Czy daloby sie zmodyfikowac skrypt tak, zeby przenosil dane z jednego pola do drugiego we wskazane miejsce? Tj. np z s1 za aktualnie zaznaczony element w s2?
EDIT:
I moze jeszcze jedna modyfikacja: zeby obslugiwal pola multiple czyli pozwalal na przenoszenie kilku wartosci na raz. Nie wiem nawet pod jakim haslem szukac - prosilbym o nakierowanie mnie.
Ssss jednak na nic mi sie to przyda :/
Moze przy okazji: czy daloby sie przeslac do skryptu php wszsytkie dane (obojetnie czy indexy czy wartosci) znajdujace sie w drugim selectcie? Zakaldam ze to bylaby jakas funkcja przypisujaca do zmiennej (np. stringa) wszystkie wartosci.
=============================================
Znalazlem odpowiednie skrypciki, polaczylem je w calosc i PRAWIE dzialaja poprawnie. Mozna przenosic po kilka pozycji na raz, mozna dodawac dane we wskazane miejsce, mozna dane przeslac do php (funkcja wyslij()). Jednak jest pewien maly problem. Otoz przenoszenie danych powoduje przeniesienie wskazanych danych + pustych pol w ilosci rownej liczbie przenoszonych pol. Nie wiem jak sie tego pozbyc. Przy wysylaniu danych przez wyslij() te puste pola nie sa juz pokazywane. Mialby ktos jakis pomysl?
<?xml version="1.0" encoding="iso-8859-2"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta name="GENERATOR" content="Quanta Plus" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /> /* <![CDATA[ */
/* ]]> */
<script language="javascript" type="text/javascript"> /* <![CDATA[ */
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
function wyslij(theSel)
{
var selLength = theSel.length;
var output = '';
for (i=0; i<selLength; i++)
{
output += theSel.options[i].text + ', ';
}
alert(output);
}
function appendOldSchool(theSel, newText, newValue)
{
if (theSel.length == 0) {
var newOpt1 = new Option(newText, newValue);
theSel.options[0] = newOpt1;
theSel.selectedIndex = 0;
} else if (theSel.selectedIndex != -1) {
var selText = new Array();
var selValues = new Array();
var selIsSel = new Array();
var newCount = -1;
var newSelected = -1;
var i;
for(i=0; i<theSel.length; i++)
{
newCount++;
selText[newCount] = theSel.options[i].text;
selValues[newCount] = theSel.options[i].value;
selIsSel[newCount] = theSel.options[i].selected;
if (newCount == theSel.selectedIndex) {
newCount++;
selText[newCount] = newText;
selValues[newCount] = newValue;
selIsSel[newCount] = false;
newSelected = newCount - 1;
}
}
for(i=0; i<=newCount; i++)
{
var newOpt = new Option(selText[i], selValues[i]);
theSel.options[i] = newOpt;
theSel.options[i].selected = selIsSel[i];
}
}
}
function addOption(theSel, theText, theValue)
{
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
}
function deleteOption(theSel, theIndex)
{
var selLength = theSel.length;
if(selLength>0)
{
theSel.options[theIndex] = null;
}
}
function moveOptions(theSelFrom, theSelTo)
{
var selLength = theSelFrom.length;
var selectedText = new Array();
var selectedValues = new Array();
var selectedCount = 0;
var i;
// Find the selected Options in reverse order
// and delete them from the 'from' Select.
for(i=selLength-1; i>=0; i--)
{
if(theSelFrom.options[i].selected)
{
selectedText[selectedCount] = theSelFrom.options[i].text;
selectedValues[selectedCount] = theSelFrom.options[i].value;
deleteOption(theSelFrom, i);
selectedCount++;
}
}
// Add the selected text/values in reverse order.
// This will add the Options to the 'to' Select
// in the same order as they were in the 'from' Select.
for(i=selectedCount-1; i>=0; i--)
{
appendOldSchool(theSelTo, selectedText[i], selectedValues[i]);
}
if(NS4) history.go(0);
}
/* ]]> */
<form action="selecty.php" method="post"> <select name="sel1" size="30" multiple="multiple" style="width: 200px;"> <td align="center" valign="middle"> <input type="button" value="-->" onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br /> <input type="button" value="<--" onclick="moveOptions(this.form.sel2, this.form.sel1);" />
<select name="sel2" size="30" multiple="multiple" style="width: 200px;"> <input type="button" value="Wyslij" onclick="wyslij(this.form.sel2);" />