1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Adding Music to a website?

Discussion in 'JavaScript' started by livingearth, Jul 4, 2008.

  1. #1
    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):

     
    livingearth, Jul 4, 2008 IP
  2. zyklon

    zyklon Active Member

    Messages:
    274
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    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...
     
    zyklon, Jul 4, 2008 IP
  3. =Messa=

    =Messa= Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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=, Jul 4, 2008 IP
  4. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #4
    @Messa
    I tried the body onload idea but I was not able to get it to work..
    Thanks it was a good idea..
     
    livingearth, Jul 4, 2008 IP
  5. =Messa=

    =Messa= Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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=, Jul 4, 2008 IP
    livingearth likes this.
  6. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #6
    @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..
     
    livingearth, Jul 5, 2008 IP
  7. =Messa=

    =Messa= Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I don't see any code.

     
    =Messa=, Jul 5, 2008 IP
  8. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #8
    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):
     
    livingearth, Jul 5, 2008 IP