Sunday, July 10, 2022

JavaScript format Date ( DD/MM/YYYY)

 Following function will check if input date is entered in DD/MM/YYYY format,  It also validates a minimum date that can be entered to an input field (original code from here)


         function IsValidDate(inputDate) {

            const regex = /^\d{2}\/\d{2}\/\d{4}$/;

            var minDate = new Date("01/01/1900 12:00:00");


            if (inputDate.match(regex) === null) {

                return false;

            }


            const [day, month, year] = inputDate.split('/');

            const isoFormattedStr = `${year}-${month}-${day}`;

            const date = new Date(isoFormattedStr);

            const timestamp = date.getTime();


            if (typeof timestamp !== 'number' || Number.isNaN(timestamp)) {

                return false;

            }


            if (isoFormattedStr < minDate.toISOString()) {

                return false;

            }


            return date.toISOString().startsWith(isoFormattedStr);

        }

Cheers
Samitha


Sunday, July 3, 2022

setInterval() and setTimeout()

If we want to execute a specific JS function after some time there are two options to use fro,.  


  • setTimeout used  run a function once after the interval specified 
  • setInterval used   run a function repeatedly, after the interval specified and repeating continuously at that interval.

If we want to stop the indefinite function call  we can use clearInterval with setInterval.


Cheers,

Samitha


Saturday, June 18, 2022

The Ultimate Guide to CSS

 I found following website to be very useful. It provides comprehensive breakdown of the CSS support for widely used email clients in both mobile and desktops. 

wfdsdfgh6    campaignmonitor.com


Regards,

Samitha

Wednesday, June 1, 2022

Get All Elements in a HTML document

 We can use Jquery or javascript to get all DOM elements


Jquery

var elements= $('*');

Javascript

var elements= document.getElementsByTagName('*');

Cheers
Samitha

Sunday, April 24, 2022

DataTable filter by date time

As per  Expression property of the DataColumn , a filter on DateTime column is created enclosing the date between the number symbol (#)

 DateTimeColumn = #dateTimeValue#

In addition the date should be formatted according to the format MM-dd-yyyy  as displayed below.


Dim strQuery = String.Format("DateExpired= #{0}#", dtExpired.ToString("MM-dd-yyyy"))    



 The query above could still fail if the columns also contain times. In such case you should change your formatting to include also output for time "HH:mm:ss" or instead  BETWEEN which is more clear.



Another workaround is use SQL CASE to check date and return a flag based ton the value as follows


SELECT 

CASE when DateExpired IS NOT NULL AND DateExpired <= Convert(date, getdate()) then 'Y' else 'N' end IsExpired



cheers

Samitha



Sunday, March 13, 2022

Allow checking only one checkbox in a group

 If we want to behave the checkbox as radio buttons we can use JS as shown below.


JS

     function CheckOnce(checkbox) {

          $("[id$='_chkLocations']").each(function (i, obj) {

              if (obj !== checkbox) obj.checked = false

              if (obj.checked) {

                 //do something

             }

          });

      }


HTML

<input type="checkbox" ID="chkLocation" onclick="CheckOnce(this)">

<input type="checkbox" ID="chkLocation" onclick="CheckOnce(this)">


Cheers

Samitha

 

Thursday, March 10, 2022

Adding visibility attribute

 There are two ways to add the visibility attribute for an element. They have a difference in the way it renedered in the HTML as shown below.


  1. $("#elementid").attr("style", "visibility: hidden")

  This will be rendered as 

style="visibility: hidden;"

 2. $("#elementid").css("visibility", "hidden")

  This will be rendered as 

style="width: 50px; color: red; visibility: hidden;"

 

 

In summary the first one will set the style attribute and the second one will append to the existing style attribute.


Cheers

Samihta