Monday, June 29, 2020

Changing Attribute “type” from text to password in Jquery Textbox

Password Input Focus Event :
Password Input Blur Event :

Sample Html Page :


<html>
    <head>
        <title>Changing Attribute type from text to password</title>
        <style type="text/css">
        </style>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script type="text/javascript">
  $(document).ready(function() {
                   $("#password_input").focus(function() {    
       $("#password_input").prop('type','text'); 
                    });
                  $("#password_input").blur(function() {        
                   $("#password_input").prop('type','password');
                });
     });
        </script>
    </head>
    <body>
        <div id="loginBox">
            <form>
             username : <input type="text" id="username_input" name="username" /><br />
             password  :<input type="text" id="password_input" name="password" /> <br />
               
            </form>
        </div>
    </body>
</html>

Copy paste function on Textbox

function copypasteonTextBox( ){
    $(target).on('paste', function (e) {
        var clipboardData = e.originalEvent.clipboardData ? e.originalEvent.clipboardData : window.clipboardData;
        var data = clipboardData.getData("text/plain");
        $(target).val(data );
        e.preventDefault();
    });
}


example
    Input :  1111222233334444

 Output  :
    TextBox1 value  :  1111
    TextBox2 value  :  2222
    TextBox3 value  :  3333
    TextBox4 value  :  4444

$('#TextBox1').on('paste', function (e) {
        var clipboardData = e.originalEvent.clipboardData ? e.originalEvent.clipboardData : window.clipboardData;
        var data = clipboardData.getData("text/plain");
        var dataAfter = $.trim(data.replace(/[^\d]/g, ''));     
        if (dataAfter.length >=15) {
$("#TextBox1 ").val(dataAfter.substr(0,4));
$("#TextBox2").val(dataAfter.substr(4,4));
$("#TextBox3").val(dataAfter.substr(8,4));
$("#TextBox2").val(dataAfter.substr(12,4));
        }     
        e.preventDefault();
    });

Split 16 digit string into 4 parts and store them in an array in C#

For example, '1111222233334444".

Method 1:

string strNumber = "1111222233334444";

string []strArr = new string[4];

for(int i=0; i < 4; i++)
{
   strArr[i] = strNumber.Substring(i*4, 4);

}

Method 2:
string initial_string = TextBox1.Text;  //read from textbox 

string [] number = new string[4];

number[0] = initial_string.Substring(0,4);
number[1] = initial_string.Substring(4,4);
number[2] = initial_string.Substring(8,4);

number[3] = initial_string.Substring(12,4);

Monday, June 22, 2020

How to use table variable in a dynamic sql statement?


create table #t (id int)

declare @value nchar(1)
set @value = N'1'

declare @sql nvarchar(max)
set @sql = N'insert into #t (id) values (' + @value + N')'

exec (@sql)

select * from #t

drop table #t

Wednesday, June 17, 2020

Row_Number() continue in Union all query

SELECT ROW_NUMBER() OVER (ORDER BY ...) AS Sno
FROM (
    SELECT
    ...
    UNION ALL
    SELECT 
    ...
) AS T
ORDER BY Sno