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

The Ultimate Guide to Interceptors: Understanding Their Power and Functionality

  The Ultimate Guide to Interceptors: Understanding Their Power and Functionality An interceptor is a service that can intercept HTTP reques...

Follow