Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7810181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:40:41+00:00 2026-06-02T03:40:41+00:00

At the moment I am using sounds on my website using an old technique

  • 0

At the moment I am using sounds on my website using an old technique with embedded tags and javascript . I want to convert these to HTML5, but I am unsuccessful doing this.

This is the code I have at the moment:

HTML:

<div class="au">
    <embed src="audio/tileSelect.wav" autostart="false" width="1" height="1" hidden="true" id="sound1" enablejavascript="true">
    <embed src="audio/tileRemove.wav" autostart="false" width="1" height="1" hidden="true" id="sound2" enablejavascript="true">
</div>

JS:

//Sounds
function playSound(soundobj) {
    if (document.getElementById('sound').checked) { //if this checkbox is checked, play sounds
        var thissound=document.getElementById(soundobj);
        thissound.Play();
    }
}

JS used in other functions to trigger the sounds:

playSound('sound1');
playSound('sound2');

So all the above works. Now to convert this to HTML5. The HTML part is easy, I think it should look like this:

HTML5:

<!--HTML5 audio-->
<audio id="sound1" preload="auto">
    <source src="audio/tileSelect.wav" type="audio/wav" />
</audio>
<audio id="sound2" preload="auto">
    <source src="audio/tileRemove.wav" type="audio/wav" />
</audio>

But for the JS part I am kinda stuck. Anyone has an idea about this? Tried to change soundobj to soundid, but had no luck with that.

Many thanks,
Maurice

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:40:41+00:00Added an answer on June 2, 2026 at 3:40 am

    There are two issues with the code you have posted.

    First one would be the markup that should probably read like this instead:

    <audio id="sound1" src="audio/tileSelect.wav" preload="auto"></audio>
    <audio id="sound2" src="audio/tileRemove.wav" preload="auto"></audio>
    

    The <video>-like source notation that you used is not documented anywhere (although I have to admit that it does not feel wrong – but then again I have never used HTML5 audio yet), see MDN documentation


    EDIT: Apparently it’s ok to use source elements inside audio elements:

    Permitted content: Transparent content, containing either a src
    attribute or one or more elements, followed by either flow
    content or phrasing content , with no or elements.

    See: https://developer.mozilla.org/en/HTML/Element/audio

    Still you don’t really need it in your case as you just have one source file.


    Second issue would be that you are using a non-existent method of .Play() (capital P), that should be called .play(). So your JS should look like:

    function playSound(soundobj) {
        if (document.getElementById('sound').checked){
            document.getElementById(soundobj).play();
        }
    }
    playSound('sound2'); //should play 'audio/tileRemove.wav'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment i'm using EJS template Engine but I need to convert it
At moment I want to implement picture upload without using any plug-ins. My upload
At the moment am using JOGL for a ball detection program I have been
At the moment I'm using JavaFX only for fun and learning it. What I
At the moment I am using OpenCV's KNN implementation to classify images. It currently
Up to this moment I was using simple arrays to enter and get necessary
I'm using jRuby at the moment (version 1.6.5) on my local machine. rvm use
I'm using the CurvyCorners for my rounded corners at the moment. I'm also using
I am using a DataGridView control in my app at the moment and I
I am using sencha touch beta 3 version at the moment. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.