Autor Zpráva
pista87
Profil
<script language="JavaScript">

function selectAllOptions(obj) {
for (var i=0; i<obj.options.length; i++) {
obj.options[i].selected = true;
}
}


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--)
{
addOption(theSelTo, selectedText[i], selectedValues[i]);
}

}

//-->
</script>

<form method=post action="">
<table border="0">
<tr>
<td>
<select name="sel1" size="10" multiple>
<option value="1">lava1</option>
<option value="2">lava2</option>
</select>
</td>
<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);" />
</td>
<td>
<select name="sel2" size="10" multiple>
<option value="1">prava1</option>
<option value="2">prava2</option>
</select>
</td>
</tr>
</table>
<input type=submit value=submit>
</form>

ako tu spracujem hodnoty zo sel2 v php? pozeral som na nete ze treba dat do toho selectu name='sel2[]' aby to bol array ale potom nefunguje to this.form.sel2 aj ked tam dam nakoniec to []

diky
centi
Profil
pista87
Nastav selectu i ID a v javascripte k nemu pristupuj práve cez ID.


<select name="sel2[]" id="mySelect">...</select>

moveOptions( document.getElementById('mySelect'), .... );


Prípadne do tej funkcie predávaj len IDčka selectov a pristupuj k nim až vo funkcii:


moveOptions( "mySelect", ...);

function moveOptions( sel1ID, sel2ID) {
var sel1 = document.getElementById( sel1ID );
....
}
pista87
Profil
okej to funguje... ale este mam jeden problem ako nastavit aby pri odoslani fomulara oznacilo cely select sel2?

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0