View Full Version : Problem with javascript text

11-02-2009, 05:30 AM
1) Script Title:

2) Script URL (on DD):

3) Describe problem: see below

I am not very good at writing javascript code so I am hoping that someone on this forum can help. Here is my situation.
On the Home page of my web site I have have the following code to send the user from the Home page to my Intro page:

<p><a href="intro.htm" > Enter </a></p>

Is it possible, using javascript, to also add a sound effect to this action? I have a sound effect in a "wave" file that I would like to hear when I click on "Enter".

As it is now I have the following in web site root folder:
-a javascript folder called "jsscripts"
-a wave file called "meow.wav"

I found the following javascript in the Dynamic Drive library:

<bgsound src="#" id="soundeffect" loop=1 autostart="true" />
<script type="text/javascript">

* JavaScript Sound effect- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use

var soundfile="sidebar.wav" //path to sound file, or pass in filename directly into playsound()

function playsound(soundfile){
if (document.all && document.getElementById){
document.getElementById("soundeffect").src="" //reset first in case of problems

function bindsound(tag, soundfile, masterElement){
if (!window.event) return
var source=event.srcElement
while (source!=masterElement && source.tagName!="HTML"){
if (source.tagName==tag.toUpperCase()){

I want to save the above javascript in my "jsscripts" folder by the file name "meow.js" and have this call my wave file when I click on "Enter".

What changes do I have to make to the above javascript and to my own current html to make my sound effect work? I have played around with the "onClick" function but am still missing something.

Hopefully I have provided you with enough information.
Thanks :)

11-02-2009, 08:33 PM
Firstly, you should be aware this script only works in IE. To get it to activate onclick, you should be able to do this just by changing the keyword onmouseover inside the HTML to onclick instead, for example:

<a href="#" onClick="playsound(soundfile)">Example 1</a>

<a href="#" onClick="playsound('different.wav')">Example 2</a>