Pages

Social Icons

Monday 10 August 2015

Strikethrough selected text JavaScript

Here is code which shows how to strike though the selected text in textbox using JavaScript.



<script type="text/javascript" language="javascript">

    function sendtext(input) {
        var striketext = '';
        var textvar = $('#txtText').val().substr(input.selectionStart, (input.selectionEnd - input.selectionStart));
        $.each(textvar.split(''), function () {
            striketext += '\u0336' + this;
        });
        var result = $('#txtText').val().substr(0, input.selectionStart) + striketext + $('#txtText').val().substr(input.selectionEnd, $('#txtText').val().length);
        $('#txtText1').val(result);
    }

</script>
<h2>Index</h2>

<input id="txtText" type="text">

<input id="txtText1" type="text">

<input type="button" value="click" onclick="sendtext(document.getElementById('txtText'))"/>