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 7593351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:08:50+00:00 2026-05-30T21:08:50+00:00

still having problems – if I get my code to play the selected audio

  • 0

still having problems – if I get my code to play the selected audio the buttons won’t toggle. If I include $(document).ready(function(){ then the button toggles but the audio won’t play! Can anyone save the little hair I have left? This is an HTML5 jQuery Mobile project for delivery on iOS 5

Thanks for any/all help
J

code:

$(document).ready(function(){
var selSound = '18000'; //default to first sound.
var play = false; //default to paused.

function selectSound(id) {
    selSound = id;
}

$('#playbtn').click(function() {
     var $this = $(this);
var a = document.getElementById(selSound);   
     if($this.text() == 'Zap!') {
    $this.children().children().text('Stop');
    a.play();
} else {
    $this.children().children().text('Zap!');
     a.pause();
    alert('Stopped playing song: '+selectedMP3);



}

});

})

html:

<div data-role="fieldcontain">       
        <fieldset data-role="controlgroup" >
                    <li data-swatch="b" class="ui-li ui-li-divider ui-btn ui-bar-a ui-corner-top" data-role="list-divider" role="" data-form="ui-bar-b">Select a frequency</li>

    <input type="radio" name="mp3_option" id="selectSound('16000')" onclick="selectSound('16000')"><label for="selectSound('16000')">16Hz</label>

    <input type="radio" name="mp3_option" id="selectSound('18000')" onclick="selectSound('18000')"><label for="selectSound('18000')">18Hz</label>

    <input type="radio" name="mp3_option" id="selectSound('20000')"    onclick="selectSound('20000')"><label for="selectSound('20000')">20Hz</label>
</fieldset>
<div style="text-align:center"><a href="#" data-role="button" data-inline="true"   id="playbtn">Zap!</a></div></div>
  • 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-05-30T21:08:52+00:00Added an answer on May 30, 2026 at 9:08 pm

    Okay, a bit of an assumption here, but I’m thinking it’s a scope issue. You need to declare the variables and function outside the document ready handler, but attach the button events inside it…

    var selSound = '18000'; //default to first sound.
    var play = false; //default to paused.
    
    function selectSound(id) {
        selSound = id;
    }
    
    $(document).ready(function(){
        $('#playbtn').click(function() {
            var $this = $(this);
            var a = document.getElementById(selSound);   
            if ($this.text() == 'Zap!') {
                $this.children().children().text('Stop');
                a.play();
            } else {
                $this.children().children().text('Zap!');
                a.pause();
                alert('Stopped playing song: ' + selectedMP3);
            }
        });
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still new to code igniter and I'm having problems getting the login system
I am still having problems with nested forms. Here is my form code: <%=
Three days had passed and still having problems to get this things work. This
I am still having problems with figuring out how to create winforms in a
I'm still having problems with loading the style sheet for these pages. Works fine
Thanks for the help below, however, I'm still having some problems, I'll try and
I'm still very new to Object Oriented programming and am having problems with the
I'm still having problems to write lambda expressions that should create some object and
Yesterday I asked this post , but I am still having problems when I
I asked about this yesterday , but I'm still having problems. I wrote 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.