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. Advertisements

  2. chris962

    McKirahan Guest

    [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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.