Thursday, 17 September 2015

How to Remove Comma Character from the Last of string.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>remove last comma from string jquery</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('.btnRemove').click(function (event) {
                var strVal = $.trim($('.txtValue').val());
                var lastChar = strVal.slice(-1);
                if (lastChar == ',') {
                    strVal = strVal.slice(0, -1);
                }
                $("#result").text(strVal);
            });
        });
    </script> 
</head>
<body>
    <div>
        <table>
            <tr>
                <td>
                    <input type="text" class="txtValue" value="I am Neeraj upadhyay, " />
                </td>
                <td>
                    <button class="btnRemove">Remove</button>
                </td>
            </tr>
            <tr>
                <td>
                    <div id="result" style="color:red;"></div>
                </td>
            </tr>  
    </div>
</body>
</html>

AdSense

Chand

  मुझे चाँद देखना पसंद है, उसे चाँद सा दिखना पसंद है। वो भी अपने दाग नहीं छुपाती, आँखों में काजल, माथे पे बिंदी नहीं लगाती। होठों को उन्...

Follow