Wednesday, 12 December 2012

Word Filter and Play Sound Using JavaScript


Word Filter and Play Sound Using JavaScript :

    <script type="text/javascript">
        function beepSound(objSound) {
            var sound = document.getElementById(objSound);
            sound.Play();

        }
        $(document).ready(function () {
            $("#btnFilter").click(function () {
            debugger
                $("#txtRead").val(filterText($("#txtwrite").val()));
            })
        });
        function filterText(sText) {
            var reBadWords = /bad|fail|tail|sad/gi;
            return sText.replace(reBadWords, function (sMatch) {
                return sMatch.replace(/./g, "*");
            });
        }
     
    </script>


HTML:

<div>
    <input type="button" id="beep" value="beep"
    onclick="beepSound('sound1');" />
    <embed src="Media/ChatBeep.wav" autostart="false" width="0"
    height="0" id="sound1" enablejavascript="true">
</div>
<div>
        <input type="text" id="txtwrite" />
        <input type="button" value="filter" id="btnFilter" />
</div>
<div>
        <input type="text" id="txtRead" />
</div>


No comments:

Post a comment