{ Snipperize } /Javascript

Javascript snippets

Here are the latest Javascript snippets. Please choose your favorite one or add a new one.

Javascript OOP Form Validator

Just thought id put up a version of my form validation class. It will be expanded in the future but I thought Id let everyone have a look.

Javascript / form, oop, validator / by ThePeppersStudio (162 days, 2.23 hours ago)

getElementBySimilarId

A simple, non-recursive function that I use to return the first element with an ID that contains a certain ID string. Sometimes, APS.NET appends the Naming Container ID to the IDs of controls, and in instances where the ClientID of a control you want is not available, you can use this script to find the element you want by similar id. Dirty, but works most of the time for me.

Javascript / getElementBySimilarId, dom, id, element / by ThePeppersStudio (168 days, 1.85 hours ago)

$ Selector

How to implement $ selector in javascript like prototype.

Javascript / $, selector / by ThePeppersStudio (168 days, 1.91 hours ago)

Viewport Size, Screen Resolution, Mouse Position

Viewport Size, Screen Resolution, Mouse Position Checker

Javascript / viewport, resolution, mouse, detect / by ThePeppersStudio (222 days, 4.68 hours ago)

Private and Privileged Members

JavaScript is fundamentally about objects. Arrays are objects. Functions are objects. Objects are objects. So what are objects? Objects are collections of name-value pairs. The names are strings, and the values are strings, numbers, booleans, and objects (including arrays and functions). Objects are usually implemented as hashtables so values can be retrieved quickly. If a value is a function, we can consider it a method. When a method of an object is invoked, the this variable is set to the object. The method can then access the instance variables through the this variable. Objects can be produced by constructors, which are functions which initialize objects. Constructors provide the features that classes provide in other languages, including static variables and methods.

Javascript / oop, private, privileged / by ThePeppersStudio (259 days, 8.26 hours ago)

Get URL Variables

Example URL: http://www.example.com/index.php?id=1&image=awesome.jpg getQueryVariable(”id”) – would return “1″. Calling getQueryVariable(”image”) – would return “awesome.jpg”.

Javascript / url, variable, query / by ThePeppersStudio (278 days, 4.53 hours ago)

Embed Image as Code

Saves an image as code. Useful for small images.

Javascript / image, base64 / by ThePeppersStudio (292 days, 5.36 hours ago)

Get PPI Of Current Device Displaying in Your Page

Outputs the number of Pixels Per Inch in the current Device

Javascript / PPI, device / by ThePeppersStudio (294 days, 5.14 hours ago)

Detecting Only Actual Text Changes OnKeydown/OnKeyup/OnKeypress

The following script will allow only keys that effect actual text changes in input/textareas (character keys, spacebar, backspace and delete). Any other key type will tell whatever function is handling the event to return and not continue on. As a result, this should be place before the actual processing portion of the function.

Javascript / detecting, key, event / by ThePeppersStudio (312 days, 6.77 hours ago)

Unique Random Number

uniqueRandomNumber(3);

Javascript / random, unique / by ThePeppersStudio (331 days, 6.90 hours ago)