Showing posts with label textbox. Show all posts
Showing posts with label textbox. Show all posts

Monday, 5 August 2013

Get multiple values from checkboxlist selected values in textbox as comma seperated using javascript in asp.net

Java Script Funtion:

function GetSelectedValue() {
        var chkBox = document.getElementById("<%=chkList.ClientID%>");
        var checkbox = chkBox.getElementsByTagName("input");
        var objTextBox = document.getElementById("<%=txtChkValue.ClientID%>");
        var counter = 0;
        objTextBox.value = "";
        for (var i = 0; i < checkbox.length; i++) {
            if (checkbox[i].checked) {
                var chkBoxText = checkbox[i].parentNode.getElementsByTagName('label');
                if (objTextBox.value == "") {
                    objTextBox.value = chkBoxText[0].innerHTML;
                }
                else {
                    objTextBox.value = objTextBox.value + ", " + chkBoxText[0].innerHTML;
                }
            }
        }

    }

where chkList is CheckboxList and txtChkValue is Textbox as given below:

<asp:TextBox ID="txtChkValue1" runat="server" CssClass="textbox"
                Width="270px" Height="25px"></asp:TextBox>
             
                <asp:CheckBoxList ID="chkList1" runat="server" onclick="GetSelectedValue1();">
                </asp:CheckBoxList>

Line/Word/Character Count in Textbox Control using Javascript funtion

JavaScript Funtion:

function LineCount(value) {
       
                    var text;
                    var lines_totals1;
                    var len;
                    var line_count;
                    var lines_totals2;
                    var diff_fli;
                    var totalCost;
                    var ExtraLine;

                    text = value;
                    lines_totals1 = Math.ceil(value.length / 23);
                    len = wordwrap(text, 23, "\n", true);
                    line_count = len.split("\n");
                    lines_totals2 = line_count.length;
                    diff_fli = lines_totals2 - lines_totals1;

                    if (diff_fli > 1) {
                        lines_totals = Math.ceil((lines_totals2 + lines_totals1) / 2);
                    }
                    else {
                        lines_totals = lines_totals2;
                    }
            }
         
        function wordcount(value) {
         
                var totalCost;
                var ExtraWord;

                var andchr = value.split(" & ").length - 1;
                var char_count = value.length;
                var fullStr = value + " ";

                //word count for regional language
                v = value.split(' ');
                var word_count = v.length;
                var cheArr = Array('@', '.', '"', "'", '_', '-', '+', '=', ';', '&', '*', '\(', '\)', '{', '}', '[', '}', '|', '\\', '\,', '/');
                for (i = 0; i <= cheArr.length; i++) {
                    word_count = word_count + value.split(cheArr[i]).length - 1;
                }

             
        }


        function charcount(value) {

         
                var totalCost;
                var ExtraWord;
                value = value.replace(/^\s+|\s+$/g, "");
                var word_count = value.length;

             

        }

Text Changed Event on Ajax HTML Editor Extender Control Textbox

Java Script to be Used :

<script type="text/javascript">
function onContentsChange12() 
        {
            //document.getElementById('Labeld21').innerText = document.getElementById('TextBoxd21').value;
    var inputText = document.getElementById('TextBoxd12').value;
    var returnText = "" + inputText;
        //-- remove BR tags and replace them with line break
    returnText=returnText.replace(/<br>/gi, "\n");
    returnText=returnText.replace(/<br\s\/>/gi, "\n");
    returnText=returnText.replace(/<br\/>/gi, "\n");

    //-- remove P and A tags but preserve what's inside of them
    returnText=returnText.replace(/<p.*>/gi, "\n");
    returnText=returnText.replace(/<a.*href="(.*?)".*>(.*?)<\/a>/gi, " $2 ($1)");

    //-- remove all inside SCRIPT and STYLE tags
    returnText=returnText.replace(/<script.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/script>/gi, "");
    returnText=returnText.replace(/<style.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/style>/gi, "");
    //-- remove all else
    returnText=returnText.replace(/<(?:.|\s)*?>/g, "");

    //-- get rid of more than 2 multiple line breaks:
    returnText=returnText.replace(/(?:(?:\r\n|\r|\n)\s*){2,}/gim, "\n\n");

    //-- get rid of more than 2 spaces:
    returnText = returnText.replace(/ +(?= )/g,'');

    //-- get rid of html-encoded characters:
    returnText=returnText.replace(/&nbsp;/gi," ");
    returnText=returnText.replace(/&amp;/gi,"&");
    returnText=returnText.replace(/&quot;/gi,'"');
    returnText=returnText.replace(/&lt;/gi,'<');
    returnText=returnText.replace(/&gt;/gi,'>');
    //-- return
    document.getElementById('Labeld12').innerHTML = returnText;
        }
</script>

paste this in header section and then write below code in body tag

<ajt:HtmlEditorExtender ID="HtmlEditorExtenderd12" runat="server" 
            TargetControlID="TextBoxd12" EnableSanitization="false"  OnClientChange="onContentsChange12">
            
        </ajt:HtmlEditorExtender>