I have a script that adds a drop down select box to a website which chooses a background music file to be played.. How can I get this script to start automatically with out losing its functionality? <div style="position:absolute;top:-5px;left:0px;"> <Table width=90% border=0 align=right valign=top><tr><td align=right valign=top><form name=choose> <font color=white> <select style="background-color: darkgray;"size=1 onChange="midiplay(this);"> <option value="#">Select Music <option value="C:\WINDOWS\system32\oobe\images\title.wma" selected="selected">Intro <option value="./tunes/indian_summer.mp3">Indian Summer <option value="./tunes/Kenny G - Songbird.mp3">Songbird </select> </form></center> </td></tr></table></div> <script language="JavaScript"> <!-- // please keep these lines on when you copy the source // made by: Nicolas - http://www.javascript-page.com document.write('<bgsound src="#" id=midijuke LOOP=INFINITE VOLUME = -500 autostart="true">'); function midiplay(what) { if (document.all) { document.all.midijuke.src = what.options[what.selectedIndex].value; } else { alert("Sorry, but the Music Menu is only accessible through MSIE4.0 and above."); } } //--> </script> Code (markup):
make the <select> have an onchange attribute, that runs a javascript script that changes what the song is. edit: it looks like ur already doing that... i am not sure what ur problem is then...
What do you mean by start the script automatically? Do you want the script to start automatically when the page loads? Well, there are many ways you can do it. I'll show you one. Put this after the "midiplay" function: document.all.midijuke.src="path\to\media\file"; Code (markup): Or better, put this as an attribute to "body" open-part tag: onload="document.all.midijuke.src='path\to\media\file';" Code (markup): <body onload="document.all.midijuke.src='path\to\media\file';"> Code (markup): Of course, replace path\to\media\file with the real path to a file.
@Messa I tried the body onload idea but I was not able to get it to work.. Thanks it was a good idea..
Well, it works and should work for you. Can you show me what path you're putting there? If e.g. you're trying "C:\sample.mp3", you need to put there "C:\\sample.mp3", with two backslashes.
@Messa Here is the code I have now.. Tryit on your desktop. If you are using XP the Intro music file should already be on your computer at the specified location..
Opps .. Dinner was calling... <html><head></head> <body bgcolor="#000000"onload="document.all.midijuke.src='C:\\WINDOWS\system32\oobe\images\title.wma';"> <div style="position:absolute;top:-5px;left:0px;"> <Table width=90% border=0 align=right valign=top><tr><td align=right valign=top><form name=choose> <font color=#ffffff> <select style="background-color: charcoal;"size=1 onChange="midiplay(this);"> <option value="#">Select Music <option value="C:\WINDOWS\system32\oobe\images\title.wma" selected="selected">Intro <option value="./tunes/indian_summer.mp3">Indian Summer <option value="./tunes/Kenny G - Songbird.mp3">Songbird </select> </form></center> </td></tr></table></div> <bgsound src="#" id=midijuke LOOP=INFINITE VOLUME = -500 autostart="true"> <script language="JavaScript"> <!-- // please keep these lines on when you copy the source // made by: Nicolas - http://www.javascript-page.com function midiplay(what) { if (document.all) { document.all.midijuke.src = what.options[what.selectedIndex].value; } else { alert("Sorry, but the Music Menu is only accessible through MSIE4.0 and above."); } } //--> </script> </body></html> Code (markup):