bandar alhajri
bandar alhajri

Reputation: 11

how to produce Beep sound in Aspx using JS based on code behind action?

simply I've .wav file and I want to run it once the textbox value changed. the textbox is placed on a aspx page. I've an HTML5 tag called :

   <audio id="audiotag1" src="Sound/Alarm1.wav" preload="auto"></audio>    
<script type="text/javascript">
    function play_single_sound() {
        document.getElementById('audiotag1').play();
    }
</script>

and the code behind is:

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "Script", "play_single_sound();", True)

they work fine if the browser support HTML5. So, I need same thing using javascript so that it work with each browser.

thanks

Upvotes: 1

Views: 535

Answers (2)

Arunprasanth K V
Arunprasanth K V

Reputation: 21941

HTML Text box
If you want to play sound in text change event then add onchange event to your text box control then in the corresponding function play the sound

 <input type="text" id="myTextBox"
        onchange="musicplay()">

Java script

<script type="text/javascript">
    function musicplay() {
        var Playsound= new Audio('Sound/Alarm1.wav');
        Playsound.play();
    }
</script>

Upvotes: 1

Saravana Kumar
Saravana Kumar

Reputation: 3729

Use this.

<script type="text/javascript">
    function play_single_sound() {
        var audio = new Audio('Alarm1.wav');
        audio.play();
    }
</script>

Upvotes: 1

Related Questions