By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,689 Members | 1,915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,689 IT Pros & Developers. It's quick & easy.

Help with playing audio files based on conditions

P: n/a
I have very basic knowledge of Javascript and am trying to get a web
page to play one of two different sound files based on whether the user
has correctly guessed a number.

At the moment, all I can make it do is display an alert.

If anyone can help with this I would really appreciate it.
Chris

This is what I've got so far (correct number is 6):
<head>
<script language="JavaScript" TYPE="TEXT/JAVASCRIPT">

function validForm(PassForm) {
if (PassForm.passwd1.value == "") {
alert("No value entered")
playsound('sound.wav')

PassForm.passwd1.focus()
return false

}
if (PassForm.passwd1.value == "6") {
alert("********* Correct number *********")
playsound('\\Poweredge\Intranet_Live\winner.mp3')

PassForm.passwd1.focus()
return true

}

if (PassForm.passwd1.value != "6") {
alert("Wrong number")
playsound('\\Poweredge\Intranet_Live\wrong.mp3')

PassForm.passwd1.focus()
return false
}

return true
}
</script>
</head>
<body>

ENTER YOUR GUESS HERE:

<form method=Get enctype="application/x-www-form-urlencoded"
onSubmit="return validForm(this)">

<p class=MsoNormal><INPUT TYPE="TEXT" NAME="passwd1"><INPUT
TYPE="SUBMIT" VALUE="Go!">&nbsp;<INPUT TYPE="RESET">
</p>

</form>
</body>

Nov 28 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"chris962" <ch***@chrisgregg.co.uk> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have very basic knowledge of Javascript and am trying to get a web
page to play one of two different sound files based on whether the user
has correctly guessed a number.

At the moment, all I can make it do is display an alert.

If anyone can help with this I would really appreciate it.
Chris

This is what I've got so far (correct number is 6):


[snip]

Will this help? Watch for word-wrap.

<html>
<head>
<title>guess.html</title>
<script type="text/javascript">
function validForm(PassForm) {
if (PassForm.passwd1.value == "") {
alert("No value entered");
playsound("sound.wav");
} else if (PassForm.passwd1.value != "6") {
alert("Wrong number");
playsound("\\Poweredge\Intranet_Live\wrong.mp3");
} else {
alert("********* Correct number *********");
playsound("\\Poweredge\Intranet_Live\winner.mp3");
return true;
}
PassForm.passwd1.focus();
return false;
}
function playsound(filename) {
var tag = "<embed src='" + filename + "' loop='false' autostart='true'
hidden>";
document.getElementById("sound").innerHTML = tag;
}
</script>
</head>
<body>
ENTER YOUR GUESS HERE:
<form method="get" onSubmit="return validForm(this)"
enctype="application/x-www-form-urlencoded">
<p class=MsoNormal>
<INPUT TYPE="TEXT" NAME="passwd1">
<INPUT TYPE="SUBMIT" VALUE="Go!">
<INPUT TYPE="RESET">
</p>
</form>
<span id="sound"></span>
</body>
</html>
Note: The <embed> tag may not work in all browsers.

1) This is all you need for the <script> tag:

<script type="text/javascript">

2) Why does you <form> tag include this?

enctype="application/x-www-form-urlencoded"

3) If this is for the Internet then you can't use this path:

\\Poweredge\Intranet_Live\

4) Is " class=MsoNormal" defined?

Is this leftover from an MS-Word export to html?

Nov 28 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.