Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Help with playing audio files based on conditions

Reply
Thread Tools

Help with playing audio files based on conditions

 
 
chris962
Guest
Posts: n/a
 
      11-28-2005
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>

 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      11-28-2005
"chris962" <> wrote in message
news: 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?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional redirects based on login status and other conditions Keith G Hicks ASP .Net 1 03-07-2008 02:45 AM
XP x64 stopped playing audio for video files Homer J. Simpson Windows 64bit 7 01-13-2007 03:57 PM
playing audio n video files AVL ASP .Net Building Controls 1 03-27-2006 06:16 PM
Playing audio n video files =?Utf-8?B?QVZM?= ASP .Net 1 03-27-2006 06:15 PM
Setting Conditions based on attribute values in XML schemas Abdul Mukit XML 0 11-17-2004 09:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57