Friday, February 3, 2023

Telerik Radeditor show remaining character count

We can use jQuery to show remaining character count for a RadEditor as shown below.  This will wok for both design and HTML modes. Here MaxTextLength is considered as the upper character limit,

JS

var textLength;

var maxTextLength;

 function radEditorOnClientLoad(editor, args) {

   maxTextLength = editor.get_maxTextLength();

    textLength = editor.get_text().length;

       if (textLength > maxTextLength)

        $('#charCountSpan' ).html("Characters Remaining: Limit Exceeded ");

    else

        $('#charCountSpan').html("Characters Remaining: " + (maxTextLength - textLength) );

    

    $(editor.get_textArea()).on("input propertychange change keyup", ChangeCharacterCount);

    $(editor.get_contentArea()).on("input propertychange change keyup", ChangeCharacterCount);

}

function ChangeCharacterCount( ) {

var editorElement = $find(<%= txtDetails.ClientID %>);

textLength = editorElement.get_text().length;

                if (textLength > maxTextLength)

                    $('#charCountSpan').html("Characters Remaining: <span class='LimitExceed'>Limit Exceeded </span>");

                else

                   $('#charCountSpan').html("Characters Remaining: " + numberWithCommas(maxTextLength - textLength));

}

HTML

 <telerik:RadEditor ID="txtDetails" runat="server" TextMode="MultiLine"   MaxTextLength ="2000" OnClientLoad="radEditorOnClientLoad" ></telerik:RadEditor>

 <span id="charCountSpan" runat ="server" class="float-right"></span>



Cheers,
Samitha

Friday, December 16, 2022

Detect input text box change

 We can use jQuery to identify input text change as shown below. This method uses setTimeout and clearTimeout to force the change event fire only after user finishes typing.

JS

var timer;
$("#title").on("input", function(e) {
  var textValue = $(this).val();
  if ($(this).data("lastvalue") != textValue ) {

    $(this).data("lastvalue", textValue );
    clearTimeout(timer);

    timer = setTimeout(function() {
      //code to handle change
      console.log(textValue);
    }, 500);
  };
});
HTML
<script src="jquery.min.js"></script>
<input type="text" id="title">

Cheers

Samitha

Wednesday, December 7, 2022

validate input type without the protocol for the url

 We can use jQuery validate to format input URL with a valid URL as shown below


rules: {

    url_field: {

      required: true,

      url: true,

      normalizer: function (value){

                value = value.replace(/^https?:\/\//, '');

                return 'http://' + value;

            }

    }

  }


Cheers

Samitha

Sunday, October 9, 2022

Add or Update query string parameter

 If we want to dynamically add or change query string,  URL API can be used as shown below

const url = new URL(location.href);

url.searchParams.set('queryStringKey', 'queryStringValue');


Cheers

Samitha



Saturday, September 17, 2022

Statistics Tool to Check Website Performance

 This is used for generating different HTTP codes. It can be useful for testing how scripts handle different responses.


Usage:

Add the status code to the URL, 

Ex: httpstat.us/200

More information can be found here.

cheers

Samitha

Tuesday, September 6, 2022

Get Client IP Address Using Jquery

  http://jsonip.com is an free API which will return IP as a json response.


 

Response sample: {"ip":"192.100.200.10","about":"/about","Pro!":"http://getjsonip.com"}

Example

$.ajax({

    type: "GET",

    async: false,

    url: "http://jsonip.com",

    success: function (data) {

        alert(data.ip);

    }

});

Saturday, August 13, 2022

SQL Server error: The server principal is not able to access the database under the current security context

 

This is a common error shown when SQL server is not mapped with the database you need to access. Follow the steps below for a resolution

  • Go to Security folder in the server.
  • Double click it and go to Logins folder.
  • Find your user id and double-click it.
  • Login Properties window will open up.
  • In that go to User Mapping.
  • Tick all the Databases that you want to map with that Login.


This can also be achieved using a SQL (specially if you are restoring a db)

USE dbNamw;
ALTER USER {userName} WITH login = {loginName}

Cheers
Samitha