...

View Full Version : combobox script changes



riptide
05-15-2007, 06:36 PM
I have a a script where I move options from a sclect list to another select list.
the problem is when I move a value from the first list it get deleted from that list and I don't want that to happen.

The second problem is the user can move options from the second list to the first one. I want them to be able to delete things from the second list. but not add it to the first list.(I almost messed up the code trying to fix that.)

The third problem is the selected index values go in to one array and the selected index text go into another array. If the user deletes something in the second box I need to have that item deleted from both of the arrays. and I don't know how to connect them.

here is the code.

<script language="JavaScript" type="text/javascript">
<!--

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

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]);
}

if(NS4) history.go(0);
}

//-->
</script>

</head>
<body>
<form action="yourpage.asp" method="post">
<table border="0">
<tr>
<td>
<select name="sel1" size="10" multiple="multiple">
<option value="1">Left1</option>
<option value="2">Left2</option>
<option value="3">Left3</option>
<option value="4">Left4</option>
<option value="5">Left5</option>
</select>
</td>
<td align="center" valign="middle">
<input type="button" value="--&gt;"
onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
<input type="button" value="&lt;--"
onclick="moveOptions(this.form.sel2,this.form.sel1);" />
</td>
<td>
<select name="sel2" size="10" multiple="multiple">
<option value="1">playlist</option>

</select>
</td>
</tr>
</table>
</form>

glenngv
05-15-2007, 09:06 PM
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);


function deleteOption(theSel)
{
var theIndex = theSel.options.selectedIndex;
if (theIndex != -1){
theSel.options[theIndex] = null;
}
}

function moveOptions(theSelFrom, theSelTo)
{
var selLength = theSelFrom.options.length;
for(var i=0; i<selLength; i++)
{
if(theSelFrom.options[i].selected)
{
if (!addOption(theSelTo, theSelFrom.options[i].text, theSelFrom.options[i].value)){
theSelFrom.options[i].selected = false; //remove selection if not duplicate and added
}
}
}

if(NS4) history.go(0);
}

function addOption(sel, txt, val){
//check if the option already exists
var dupe=false;
for (var i=0; i<sel.options.length; i++){
if (sel.options[i].value==val && sel.options[i].text==txt){
dupe=true;
break;
}
}
if (!dupe){ //add the option at the end
sel.options[sel.options.length] = new Option(txt, val);
setTimeout(function(){sel.options[sel.options.length-1].selected=true;},10); //delay selection in order for the combobox to scroll (if any) to the bottom.
}
return dupe;
}
//-->
</script>

</head>
<body>
<form action="yourpage.asp" method="post">
<table border="0">
<tr>
<td>
<select name="sel1" size="10" multiple="multiple" onchange="this.form.sel2.selectedIndex=-1;">
<option value="1">Left1</option>
<option value="2">Left2</option>
<option value="3">Left3</option>
<option value="4">Left4</option>
<option value="5">Left5</option>
</select>
</td>
<td align="center" valign="middle">
<input type="button" value="--&gt;"
onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
<input type="button" value="&lt;--"
onclick="deleteOption(this.form.sel2);" />
</td>
<td>
<select name="sel2" size="3" multiple="multiple" onchange="this.form.sel1.selectedIndex=-1;">
<option value="1">playlist</option>

</select>
</td>
</tr>
</table>
</form>
</body>
</html>

riptide
05-16-2007, 01:49 AM
and this does deleate the values of an deleted item from the array.

by the way is there a way to delete all the items from an array. I was thinking something using a for loop.

riptide
05-16-2007, 02:44 PM
works fine but I had added the embedding windows media player cross browser script from this site to my old code. It worked but in your cose it dosen't work.
http://codingforums.com/showthread.php?t=50666&page=3

let me show you what I did to your code.

<script language="JavaScript" type="text/javascript">
<!--

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);


function deleteOption(theSel)
{
var theIndex = theSel.options.selectedIndex;
if (theIndex != -1){
theSel.options[theIndex] = null;
}
}

function moveOptions(theSelFrom, theSelTo)
{
var selLength = theSelFrom.options.length;
for(var i=0; i<selLength; i++)
{
if(theSelFrom.options[i].selected)
{
if (!addOption(theSelTo, theSelFrom.options[i].text, theSelFrom.options[i].value)){
theSelFrom.options[i].selected = false; //remove selection if not duplicate and added
}
}
}

if(NS4) history.go(0);
}

function addOption(sel, txt, val){
//check if the option already exists
var dupe=false;
for (var i=0; i<sel.options.length; i++){
if (sel.options[i].value==val && sel.options[i].text==txt){
dupe=true;
break;
}
}
if (!dupe){ //add the option at the end
sel.options[sel.options.length] = new Option(txt, val);
setTimeout(function(){sel.options[sel.options.length-1].selected=true;},10); //delay selection in order for the combobox to scroll (if any) to the bottom.
}
return dupe;
}
//-->
function song(){
document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='music2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+document.getElementById('userChoose').value+"' name='MediaPlayer1' width='300' height='75' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true'></embed>";
}

</script>

</head>
<body>
<form action="yourpage.asp" method="post">
<table border="0">
<tr>
<td>
<select name="sel1" size="10" multiple="multiple" onchange="this.form.sel2.selectedIndex=-1;" id="misterio">
<option value="Rihanna - Umbrella ft. Jay-Z.mp3">Left1</option>
<option value="Rihanna - Umbrella ft. Jay-Z.mp3">Left2</option>
<option value="3">Left3</option>
<option value="4">Left4</option>
<option value="5">Left5</option>
</select>
</td>
<td align="center" valign="middle">
<input type="button" value="--&gt;"
onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
<input type="button" value="&lt;--"
onclick="deleteOption(this.form.sel2);" />
<input type="button" onclick="song()" />
</td>
<td>
<select name="sel2" size="3" multiple="multiple" onchange="this.form.sel1.selectedIndex=-1;" id="userChoose">
<option value="1">playlist</option>

</select>
</td>
</tr>
</table>
</form>
<div id="music1">
<object width="235" height="160"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">
<param name="URL" value="">
<param name="AutoStart" VALUE="True">
<param name="uiMode" value="full">
<embed type="application/x-mplayer2"
src=""
ShowControls="1"
width="235"
height="160">
</embed>
</object>
</div>

</body>

glenngv
05-16-2007, 06:45 PM
Move the //--> right before the </script> tag.

//-->
function song(){
document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='music2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+document.getElementById('userChoose').value+"' name='MediaPlayer1' width='300' height='75' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true'></embed>";
}

</script>

riptide
05-16-2007, 08:22 PM
glenngv, have you improved your WMP code by the way I saw some one say something about the code playing all of their options although they didn't want it to.

well I want it to play every option that was moved to the second select forum.(sel2)
with out having to push play all the time.

also
<input type="button" onclick="Play()" />
<input type="button" onclick="Pause()" />
<input type="button" onclick="Stop()" />

don't work even with
<embed type="application/x-mplayer2"
src=""
ShowControls="1"
width="250"
enableJavaScript="true"
height="50">
</embed>


I think I'm missing some of the code. I heard the functions stop,play and, pause were already defined.

riptide
05-17-2007, 04:23 PM
I'm having so many problems.
The code works but I want it to play all the options in the second select list.
so I added something that selects all the options in the second list. Even though they are selected. It only plays the first selected song. I looked all over to fix that problem but found nothing. I wonder if the second box should be something else but other forum objects don't carry the value for every thing in them. maybe I should put the values in an array and have the player play it out of there.

But glenngv you took out the arrays. Did you take them out because the value wasn't passing to the second select list. because the player actually only worked when I connected it to the first list. when you chaged the code the player could play songs from the second list and first list.

here is what it looks like now.

<script language="JavaScript" type="text/javascript">
<!--

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);


function deleteOption(theSel)
{
var theIndex = theSel.options.selectedIndex;
if (theIndex != -1){
theSel.options[theIndex] = null;
}
}

function moveOptions(theSelFrom, theSelTo)
{
var selLength = theSelFrom.options.length;
for(var i=0; i<selLength; i++)
{
if(theSelFrom.options[i].selected)
{
if (!addOption(theSelTo, theSelFrom.options[i].text, theSelFrom.options[i].value)){
theSelFrom.options[i].selected = false; //remove selection if not duplicate and added
}
}
}

if(NS4) history.go(0);
}

function addOption(sel, txt, val){
//check if the option already exists
var dupe=false;
for (var i=0; i<sel.options.length; i++){
if (sel.options[i].value==val && sel.options[i].text==txt){
dupe=true;
break;
}
}
if (!dupe){ //add the option at the end
sel.options[sel.options.length] = new Option(txt, val);
setTimeout(function(){sel.options[sel.options.length-1].selected=true;},10); //delay selection in order for the combobox to scroll (if any) to the bottom.
}
return dupe;
}

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



function song(){
document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='music2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+document.getElementById('userChoose').value+"' name='MediaPlayer1' width='300' height='75' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true'></embed>";
}
//-->
</script>

</head>
<body>
<form action="yourpage.asp" method="post">
<table border="0">
<tr>
<td>
<select name="sel1" size="10" multiple="multiple" onchange="this.form.sel2.selectedIndex=-1;" id="misterio">
<option value="Rihanna - Umbrella ft. Jay-Z.mp3">Left1</option>
<option value="Seal - Kiss From A Rose.mp3">Left2</option>
<option value="3">Left3</option>
<option value="4">Left4</option>
<option value="5">Left5</option>
</select>
</td>
<td align="center" valign="middle">
<input type="button" value="--&gt;"
onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
<input type="button" value="&lt;--"
onclick="deleteOption(this.form.sel2);" />
<input type="button" onclick="selectAllOptions('sel2');song()" />
<input type="button" onclick="music1.pause()" />
<input type="button" onclick="music1.stop()" />
</td>
<td>
<select name="sel2" size="3" multiple="multiple" onchange="this.form.sel1.selectedIndex=-1;" id="userChoose">
<option value="1">playlist</option>

</select>
</td>
</tr>
</table>
</form>
<div id="music1">
<object width="250" height="59"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">
<param name="URL" value="">
<param name="AutoStart" VALUE="True">
<param name="uiMode" value="full">
<embed type="application/x-mplayer2"
src=""
ShowControls="1"
width="250"
height="50">
</embed>
</object>
</div>

glenngv
05-17-2007, 04:59 PM
Do you want to play the songs one after the other? How would you know if a song finishes playing?

riptide
05-17-2007, 06:48 PM
when I tried to make this code from scratch I ran in to the same problem.

in the end I tried to use a time out function that plays a new song after 6minutes

but I still need to get the values into the array but if the user deletes a song from the second select list will the song be removed from the array.

that was one of the biggest problems because you don't know what order the array will be in so using functions of the array won't work.

is there another way to fix those two problems.

glenngv
05-17-2007, 09:29 PM
Try this:

var ctr=1;
function playSongs(){
var arr, len;
var sel = document.forms[0].sel2;
var defaultLen = 360; //6 mins
if (ctr<sel.options.length){
arr = sel.options[ctr].value.split("|");
if (arr.length>0 && arr[0]){
len = (Number(arr[1]))? Number(arr[1])*1000:defaultLen*1000; //in milliseconds
document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='music2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+arr[0]+"' name='MediaPlayer1' width='300' height='75' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true'></embed>";
}
ctr++;
setTimeout("playSongs()", len);
}
}

<select name="sel1" size="10" multiple="multiple" onchange="this.form.sel2.selectedIndex=-1;" id="misterio">
<option value="Rihanna - Umbrella ft. Jay-Z.mp3|300">Left1</option>
<option value="Seal - Kiss From A Rose.mp3|250">Left2</option>
<option value="whatever.mp3|200">Left3</option>
<option value="whatever2.mp3|">Left4</option>
<option value="whatever3.mp3">Left5</option>
</select>
...
<input type="button" value="Play" onclick="playSongs()" />
You can specify the length (in seconds) of the song (if you know it) in the option value delimited by '|'. If you don't know the length, you can leave it blank and it will default to 6 minutes.

riptide
05-17-2007, 10:52 PM
hum.....no error but it won't play. I was looking over option.length earlier. If you could use something like options.lengh.vaue I bet it would play. But the thing is I don't think the vaules from the options are being passed to the player.


<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<script language="JavaScript" type="text/javascript">



<!--

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);


function deleteOption(theSel)
{
var theIndex = theSel.options.selectedIndex;
if (theIndex != -1){
theSel.options[theIndex] = null;
}
}

function moveOptions(theSelFrom, theSelTo)
{
var selLength = theSelFrom.options.length;
for(var i=0; i<selLength; i++)
{
if(theSelFrom.options[i].selected)
{
if (!addOption(theSelTo, theSelFrom.options[i].text, theSelFrom.options[i].value)){
theSelFrom.options[i].selected = false; //remove selection if not duplicate and added
}
}
}

if(NS4) history.go(0);
}

function addOption(sel, txt, val){
//check if the option already exists
var dupe=false;
for (var i=0; i<sel.options.length; i++){
if (sel.options[i].value==val && sel.options[i].text==txt){
dupe=true;
break;
}
}
if (!dupe){ //add the option at the end
sel.options[sel.options.length] = new Option(txt, val);
setTimeout(function(){sel.options[sel.options.length-1].selected=true;},10); //delay selection in order for the combobox to scroll (if any) to the bottom.
}
return dupe;
}

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

var ctr=1;
function playSongs(){
var arr, len;
var sel = document.forms[0].sel2;
var defaultLen = 360; //6 mins
if (ctr<sel.options.length){
arr = sel.options[ctr].value.split("|");
if (arr.length>0 && arr[0]){
len = (Number(arr[1]))? Number(arr[1])*1000:defaultLen*1000; //in milliseconds
document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='music2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+arr[0]+"' name='MediaPlayer1' width='300' height='75' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true'></embed>";
}
ctr++;
setTimeout("playSongs()", len);
}
}



//-->
</script>

</head>
<body>
<form action="yourpage.asp" method="post">
<table border="0">
<tr>
<td>


<select name="sel1" size="10" multiple="multiple" onchange="this.form.sel2.selectedIndex=-1;" id="misterio">
<option value="Rihanna - Umbrella ft. Jay-Z.mp3|300">Left1</option>
<option value="Seal - Kiss From A Rose.mp3|250">Left2</option>
<option value="whatever.mp3|200">Left3</option>
<option value="whatever2.mp3|">Left4</option>
<option value="whatever3.mp3">Left5</option>
</select>


</td>
<td align="center" valign="middle">
<input type="button" value="--&gt;"
onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
<input type="button" value="&lt;--"
onclick="deleteOption(this.form.sel2);" />
<input type="button" value="Play" onclick="playSongs()" />



</td>
<td>
<select name="sel2" size="3" multiple="multiple" onchange="this.form.sel1.selectedIndex=-1;" id="userChoose">
<option value="1">playlist</option>

</select>
</td>
</tr>
</table>
</form>
<div id="music1">
<object width="250" height="59" id="Player"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">
<param name="URL" value="">
<param name="autoStart" VALUE="true">
<param name="uiMode" value="full">
<param name="currentPosition" vaule="1" >
<param name="ShowStatusBar" value="true" >
<embed type="application/x-mplayer2"
src=""
ShowControls="0"
width="250"
height="50">
</embed>
</object>

<input type="button" name="PlayMedia" value="Play" OnClick="StartMediaUp()">
<input type="button" name="StopMedia" value="Stop" OnClick="ShutMediaDown()">

<P>This example shows a minimally-functional player

<script>
<!--

function StartMediaUp ()
{
document.Player.URL = "preludesteel.wma";
document.Player.controls.play();
}

function ShutMediaDown ()
{
document.Player.controls.stop();
}

-->
</script>


</div>

</body>

glenngv
05-18-2007, 02:47 PM
Debug it by doing an alert.

var ctr=1;
function playSongs(){
var arr, len;
var sel = document.forms[0].sel2;
var defaultLen = 360; //6 mins
if (ctr<sel.options.length){
arr = sel.options[ctr].value.split("|");
alert("song:"+arr[0]);
if (arr.length>0 && arr[0]){
len = (Number(arr[1]))? Number(arr[1])*1000:defaultLen*1000; //in milliseconds
document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='music2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+arr[0]+"' name='MediaPlayer1' width='300' height='75' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true'></embed>";
}
ctr++;
setTimeout("playSongs()", len);
}
}
Change the red part to the same tags (<object> and <embed>) as the one you used in the body.

riptide
05-18-2007, 04:38 PM
hum.....
when I use music2 the alert comes up when I pust he play button. it gives the song file.

when I use Player (the one in the body of the page) it does the samething
but both times when I move the first song the alert never comes up. only the second songs file name comes up. but I know it's because I removed Playlist
I really wasn't going to have that in there. I'll use a fieldset and lable to add playlist.

If this is collecting the values from everything in the second select list something is wrong. it still won't play one song after another. If I push play after it stops it plays the same song again.

glenngv
05-18-2007, 04:54 PM
To play the first song, change this:

var ctr=1;
to

var ctr=0;

riptide
05-18-2007, 07:09 PM
kay. I was thinking the problem with playing all of the songs. do you think this is a part of windows media player scripting. if you saw the first post in the windows media player embeding topic the person said it would play everything.
I really don't why this code dosen't work.

riptide
05-19-2007, 04:01 PM
even though I used the select all function. The player still sees it as only one selected item and only plays the one selected.
I know dealing with muti select forums dosen't send all the selected items you have to use a for loop to get all the items. Not just a for loop to select all the options.but even still I don't know if it would work. some how I think it would play all the songs if the vaues were passed to an array. But the problem is can you remove an item from the array corresponding to a text value displayed in a select object if the user deletes it.

riptide
05-20-2007, 08:11 PM
this is not my code and it dosen't work. but from what I see they tried to play music from an array. but it looks like they tried to connect the array to the select list. I'm trying to see if windows media player will play all the songs if they're in an array.

<script type="text/javascript">

<!-- Begin
var playstate = 1;
shuffle = 0; // set to 0 to always play first video in list
// set to 1 to randomly choose the first video to play
videos=new array();
videos[0]="02 - TOOL - 10000 DAYS - JAMBI.mp3";
videos[1]="Megadeath - A Tout Le Monde.mp3";
videos[2]="archive/DSR.EP3.wmv";
videos[3]="archive/DSR.EP4.wmv";
videos[4]="archive/DSR.EP5.wmv";
if (shuffle == 1) {
var randsg = Math.floor(Math.random()*videos.length);
document.dsrmotion.fileName = videos[randsg];
document.dsrmotion.scr = videos[randsg];
document.forms['form'].playlist.options[randsg].selected = true;
}
function play(list) {
if (playstate == 2) {
document.dsrmotion.play();
} else {
var snum = list.options[list.selectedIndex].value
document.dsrmotion.fileName = videos[snum];
document.dsrmotion.scr = videos[snum];
}
playstate = 1;
}
// End -->
</Script>

<object width="220" height="160" id="dsrmotion" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" type="application/x-oleobject" standby="Loading Microsoft windows media player components..." classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">
<param name value>
<param name="ShowControls" value="0">
<param name="ShowStatusBar" value="0">
<param name="ShowDisplay" value="0">
<param name="DefaultFrame" value="Slide">
<param name="Autostart" value="1">
<param name="Loop" value="False">
<embed width="220" height="160" id="dsrmotion" type="video/x-ms-asf-plugin" transparentatstart="true" SendOpenStateChangeEvents="true" showstatusbar="1" showdisplay="0" autosize="0" autorewind="0" animationstart="0" autostart="0" showcontrols="0">
</object>

<form name="form">
<select style="FONT-SIZE: 8pt; BACKGROUND:#transparent; WIDTH: 150px; COLOR: #33666; font-face: verdana" name="playlist" size="1">
<option value="0">Video 1</option>
<option value="1">Video 2</option>
<option value="2">Video 3</option>
<option value="3">Video 4</option>
<option value="4">Video 5</option>
</select><br>
<img TYPE="BUTTON" NAME="darkplay" VALUE="play" TITLE="play" OnClick="play(document.forms['form'].playlist);" src="images/playbutton.jpg" width="27" height="26">
<img TYPE="BUTTON" NAME="darkpause" VALUE="pause" TITLE="Pause" onClick="document.dsrmotion.Pause(); playstate=2;" src="images/pausebutton.jpg" width="30" height="26">
<img TYPE="BUTTON" NAME="darkstop" VALUE="stop" TITLE="Stop" OnClick="document.dsrmotion.Stop(); playstate=2;" src="images/stopbutton.jpg" width="27" height="26">
</form>

riptide
05-21-2007, 04:12 PM
ignore my last post I wasn't thinking right.

can I have a button that sends the values of the second select list to an array when the user pushes a button. and have another button to delete what's in that array.

can windows media player then play music from the array and not the select list. I think no matter what we do to the options in the selectlist WMP still will only play what is selected.

so show you what I mean here is a code with the songs up loaded so you can test it out

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<script language="JavaScript" type="text/javascript">



<!--

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);


function deleteOption(theSel)
{
var theIndex = theSel.options.selectedIndex;
if (theIndex != -1){
theSel.options[theIndex] = null;
}
}

function moveOptions(theSelFrom, theSelTo)
{
var selLength = theSelFrom.options.length;
for(var i=0; i<selLength; i++)
{
if(theSelFrom.options[i].selected)
{
if (!addOption(theSelTo, theSelFrom.options[i].text, theSelFrom.options[i].value)){
theSelFrom.options[i].selected = false; //remove selection if not duplicate and added
}
}
}

if(NS4) history.go(0);
}

function addOption(sel, txt, val){
//check if the option already exists
var dupe=false;
for (var i=0; i<sel.options.length; i++){
if (sel.options[i].value==val && sel.options[i].text==txt){
dupe=true;
break;
}
}
if (!dupe){ //add the option at the end
sel.options[sel.options.length] = new Option(txt, val);
setTimeout(function(){sel.options[sel.options.length-1].selected=true;},10); //delay selection in order for the combobox to scroll (if any) to the bottom.
}
return dupe;
}

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

var ctr=0;
function playSongs(){
var arr, len;
var sel = document.forms[0].sel2;
var defaultLen = 360; //6 mins
if (ctr<sel.options.length){
arr = sel.options[ctr].value.split("|");
alert("song:"+arr[0]);
if (arr.length>0 && arr[0]){
len = (Number(arr[1]))? Number(arr[1])*1000:defaultLen*1000; //in milliseconds
document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='Player' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+arr[0]+"' name='MediaPlayer1' width='300' height='75' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true'></embed>";
}
ctr++;
setTimeout("playSongs()", len);
}
}



//-->
</script>

<style type="text/css">
<!--
#thebuttons {
position: absolute;
}
#music1 {
position: absolute;
}
-->
</style>
</head>
<body>
<fieldset >

<form action="yourpage.asp" method="post">


<select name="sel1" size="10" multiple="multiple" onchange="this.form.sel2.selectedIndex=-1;" id="misterio">
<option value="http://www.fileden.com/files/2006/11/20/398972/HIM%20-%20Dark%20Light%20-%2004%20-%20Killing%20Loneliness.mp3|300">him</option>
<option value="http://www.fileden.com/files/2006/11/20/398972/02%20-%20TOOL%20-%2010000%20DAYS%20-%20JAMBI.mp3|450">tool</option>
<option value="http://www.fileden.com/files/2006/11/20/398972/Seal%20-%20Kiss%20From%20A%20Rose.mp3|300">seal</option>
<option value="whatever2.mp3|">Left4</option>
<option value="whatever3.mp3">Left5</option>
</select>

<fieldset id="thebuttons">

<input type="button" value="--&gt;"
onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
<input type="button" value="&lt;--"
onclick="deleteOption(this.form.sel2);" />
<input type="button" value="Play" onclick="playSongs()" />
<input type="button" value="playall" onclick="selectAllOptions('sel2')"/>
</fieldset>

<select name="sel2" size="3" multiple="multiple" onchange="this.form.sel1.selectedIndex=-1;" id="userChoose">


</select>

</form>

<div id="music1">
<object width="250" height="59" id="Player"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">
<param name="URL" value="">
<param name="autoStart" VALUE="true">
<param name="uiMode" value="full">
<param name="currentPosition" vaule="1" >
<param name="ShowStatusBar" value="true" >
<embed type="application/x-mplayer2"
src=""
ShowControls="0"
width="250"
height="50">
</embed>
</object>

<input type="button" name="PlayMedia" value="Play" OnClick="StartMediaUp()">
<input type="button" name="StopMedia" value="Stop" OnClick="ShutMediaDown()">

<P>This example shows a minimally-functional player



</div>
</fieldset>
</body>

glenngv
05-21-2007, 04:36 PM
The code for the playSongs() function that I gave you should play the songs one after the other even without selecting all the options. You don't need to select them to play them. Whatever items in the select will be played one after the other. No need for the array. The only thing you need to change in the code is the innerHTML of 'music1' div. It should be set to:


document.getElementById('music1').innerHTML='<object width="250" height="59" id="Player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject"><param name="URL" value="'+arr[0]+'"><param name="autoStart" VALUE="true"><param name="uiMode" value="full"><param name="currentPosition" vaule="1" ><param name="ShowStatusBar" value="true" ><embed type="application/x-mplayer2" src="'+arr[0]+'" ShowControls="0" width="250" height="50"></embed></object>';

riptide
05-21-2007, 08:23 PM
it works....heay why wasn't it working before?

I'll take out the play button and the select all function.

thanks

glenngv
05-21-2007, 08:35 PM
Because you were only using <embed> before and you must be running it in IE. Embed is for Netscape, Firefox and probably other browsers out there. I told you even in my earlier post that you need to change embed to object + embed.

riptide
05-22-2007, 03:29 PM
yeah I see that now. I have firefox too it is a cross browser script but it doesn't display the player in firefox. it's a black rectangle.

by the way something strange happened when I added it to a forum.
I know your script works fine but I'm just going to ask you if you have any ideas why you script may not be working in this page. I also have another error over a working rollover.

here is the site...it's not done.
http://riptidekryp.9.forumer.com/

glenngv
05-22-2007, 08:20 PM
You didn't include the script that contains the needed functions such as playSongs(), moveOptions(), addOption() and deleteOption(). If you look at the Javascript Console of Firefox, you will see useful error messages that will help you solve it on your own.

riptide
05-22-2007, 11:53 PM
all the script were added to the forums. but it must not be in the right place or something because it's not being sent.

Now it's in the page but it's still wont play in firefox only. Does your code have to be in the head of the page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum