Using jQuery to prevent Internet Explorer from accidentally submitting form on enter key

$(function () {
    //page is ready
	
	
		//Prevents users from accidentally submitting form with enter key (e.g. IE problem) 
	    //http://stackoverflow.com/questions/895171/prevent-users-from-submitting-form-by-hitting-enter
	    $(document).on("keyup keypress", "form input[type='text']", function (e) {
	        if (e.keyCode === 13 /*enterkey*/ || event.keyCode === 169 /*enter on numpad*/) {
	            e.preventDefault();
	            return false;
	        }
	    });
	
});

Works in ajax templated context as well.

Javascript Parser extension – function list and lint

Ever wanted a simple overview of your javascript functions in Visual Studio 2013? This extension fixes that.

Especially useful if you use namespacing a lot and wants a simple navigation inside the js file.

Its also a “linter” which tells you about faulty js code.

Untitled

 

You can tweak the settings in Visual Studio options:

Screenshot - 2015-04-27 , 09_01_06

Javascript Parser extension.

String.format for javascript (C# .NET like syntax for concatenating strings)

Here is a little hack to make javascript behave more like .NET with string.format…

usage:

var selector = String.format("#container{0} div.lineItem{1}[data-entryid='{2}']", containerId, itemId, entryId);

js code:

//String.format for js.
if (!String.format) {
String.format = function (format) {
var args = Array.prototype.slice.call(arguments, 1);
return format.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}

From: http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format/4673436#4673436

Create Bookmarklets – The Right Way – Tuts+ Code Tutorial

Bookmarkets can be defined as mini applications masquerading as tiny snippets of JavaScript awesomeness that reside in your browser and provide additional functionalities to a web page.

Today, we’re going to look into creating bookmarklets from scratch and on the way, some best practices to follow.”

via Create Bookmarklets – The Right Way – Tuts+ Code Tutorial.