Help with playing audio files based on conditions

Discussion in 'Javascript' started by chris962, Nov 28, 2005.

  1. chris962

    chris962 Guest

    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>
    chris962, Nov 28, 2005
    #1
    1. Advertising

  2. chris962

    McKirahan Guest

    "chris962" <> wrote in message
    news:...
    > 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?
    McKirahan, Nov 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QVZM?=

    Playing audio n video files

    =?Utf-8?B?QVZM?=, Mar 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    347
    Steve C. Orr [MVP, MCSD]
    Mar 27, 2006
  2. Ravi Kosuri
    Replies:
    0
    Views:
    463
    Ravi Kosuri
    Aug 4, 2003
  3. Phil Staite
    Replies:
    5
    Views:
    648
    Roedy Green
    Sep 20, 2005
  4. Ryan Kremser
    Replies:
    1
    Views:
    645
    Thomas Matthews
    Oct 27, 2003
  5. AVL

    playing audio n video files

    AVL, Mar 26, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    107
    Steve C. Orr [MVP, MCSD]
    Mar 27, 2006
Loading...

Share This Page