Archive

Author Archive

Set focus on textbox

November 16, 2016 Leave a comment

Using Jquery

$(function() {
  $("#Box1").focus();
});

Using Javascript
window.onload = function() {
  document.getElementById("Box1").focus();
};

HTML5 
<input type="text" name="fname" autofocus>
Categories: ASP.NET

Disable click outside of bootstrap model area to close modal


Problem :You can close the modal by clicking on the background. Is there anyway to disable this feature? On specific modals only?

Solution :

There is option called backdrop. Passing this option with value 'static' will prevent closing the modal.
Also can pass {keyboard: false} to prevent closing the modal by pressing Esc.

[1] If you opening the modal by js use:
$
('#myModal').modal({backdrop: 'static', keyboard: false})

[2] If you are using data attributes, use:
<button data-target="#myModal" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    Launch demo modal
</button>`

 

 

AngularJS: Get selected Text and Value of HTML Select DropDownList using ng-change


The below HTML Markup consists of an HTML DIV to which ng-app and ng-controller AngularJS directives have been assigned.

The HTML DIV consists of an HTML Select DropDownList which will be populated from JSON array using ng-options directive.

The HTML Select DropDownList has been assigned ng-change directive. When an option is selected in HTML Select DropDownList then the GetValue function of the Controller gets called.
Inside the function, first the selected Value is fetched from the ng-model attribute and the selected Text is fetched from the JSON array using jQuery grep function.
Finally the selected Text and Value is displayed using JavaScript alert message box.

2016-06-21_1554

Age calculation in mysql Select query


Following is the way to calculate age based on date in mysql select query

SELECT name, birth, CURDATE(), TIMESTAMPDIFF(YEAR,birth,CURDATE()) AS age FROM TableName;
+----------+------------+------------+------+
| name     | birth      | CURDATE()  | age  |
+----------+------------+------------+------+
| Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
| Claws    | 1994-03-17 | 2003-08-19 |    9 |
| Buffy    | 1989-05-13 | 2003-08-19 |   14 |
| Fang     | 1990-08-27 | 2003-08-19 |   12 |
| Bowser   | 1989-08-31 | 2003-08-19 |   13 |
| Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
| Whistler | 1997-12-09 | 2003-08-19 |    5 |
| Slim     | 1996-04-29 | 2003-08-19 |    7 |
| Puffball | 1999-03-30 | 2003-08-19 |    4 |
+----------+------------+------------+------+

Hope this is helpful !

Function to find dates in current week in mysql


MySQL YEARWEEK() returns year and week number for a given date.

Syntax: YEARWEEK(date_value,Mode)

Parameters or Arguments

date_value
A date or datetime value from which to extract the year and week.
mode
Optional. It is used to specify what day the week starts on. It can be one of the following:

mode Explanation Week Value
0 First day of the week is Sunday 0-53
1 First day of the week is Monday and the first week has more than 3 days 0-53
2 First day of the week is Sunday 1-53
3 First day of the week is Monday and the first week has more than 3 days 1-53
4 First day of the week is Sunday and the first week has more than 3 days 0-53
5 First day of the week is Monday 0-53
6 First day of the week is Sunday and the first week has more than 3 days 1-53
7 First day of the week is Monday 1-53

Example : select YEARWEEK(now());

The following statement will return the year and week number of the date 2016-05-19.

SELECT YEARWEEK(‘2016-05-19’);

 

mysql-yearweek-function

 

Hope this help!

HEX Color Code Converter / Chooser

March 29, 2016 Leave a comment

Unable to launch the ASP.NET Development server because port ‘1900’ is in use


The Problem

You are coding away, Visual Studio locks up for one of it’s many reasons, and reopen your project and run it again. You then get the “Unable to launch the visual studio development server because port 9452 is in use” error

The Cause

When Visual Studio crashed, the Web Server did not, so basically it thinks you are trying to run two instances at the same time, which is not allowed.

The Solution

Open up the process manager, go to the Processes tab, and select “WebDev.WebServer40.exe” and click “End Process”. Then try running your project again. Visual Studio will now start the project fresh and the problem should go away.

1

Or try this

2jpg

 

Hope it helps !