Skip to content

Instantly share code, notes, and snippets.

@danwill
danwill / ageCheck.js
Last active October 27, 2023 10:55
Javascript: Age validation with jquery.validate.js #snippet
$.validator.addMethod("checkage", function(value, element, params) {
var subDate, userDate, today, diff;
subDate = getSubmittedDate(); // some function that returns the user's birthdate as a Date
userDate = new Date((subDate.getFullYear() + params), subDate.getMonth(), subDate.getDate());
today = new Date();
diff = today.getTime() - userDate.getTime();
return diff > -1;
}, "You must be over " + params.toString() + " to enter");
$('#my-form').validate({
@danwill
danwill / detect_network.html
Last active December 11, 2015 23:38
Javascript: Detect network connectivity #snippet
<!-- Make sure you add the manifest to your html document -->
<html manifest="myapp.appcache">
@danwill
danwill / dob_form_controls.js
Last active January 9, 2023 04:15
Javascript: Date of birth form control population #snippet
var monthList, startYear;
monthList = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
$('select[name$="dob_month"]').each(function() {
for (var i = 0; i < monthList.length; i = i+1) {
$(this).append('<option value="'+ String(i) +'">' + String(monthList[i]) + '</option>');
}
});
$('select[name$="dob_day"]').each(function() {
@danwill
danwill / US_state_list.js
Last active December 11, 2015 23:38
Javascript: US State List with jQuery binding #snippet
var stateList = {
AL: "Alabama", AK: "Alaska", AZ: "Arizona", AR: "Arkansas", CA: "California", CO: "Colorado", CT: "Connecticut", DE: "Delaware", FL: "Florida", GA: "Georgia", HI: "Hawaii", ID: "Idaho", IL: "Illinois", IN: "Indiana", IA: "Iowa", KS: "Kansas", KY: "Kentucky", LA: "Louisiana", ME: "Maine", MD: "Maryland", MA: "Massachusetts", MI: "Michigan", MN: "Minnesota", MS: "Mississippi", MO: "Missouri", MT: "Montana",NE: "Nebraska", NV: "Nevada", NH: "New Hampshire", NJ: "New Jersey", NM: "New Mexico", NY: "New York", NC: "North Carolina", ND: "North Dakota", OH: "Ohio", OK: "Oklahoma", OR: "Oregon", PA: "Pennsylvania", RI: "Rhode Island", SC: "South Carolina", SD: "South Dakota", TN: "Tennessee", TX: "Texas", UT: "Utah", VT: "Vermont", VA: "Virginia", WA: "Washington", WV: "West Virginia", WI: "Wisconsin", WY: "Wyoming"
};
// Will populate any select element whose name ends with 'state'
$('select[name$="state"]').each(function() {
for (abbr in stateList) {
if (stateList.hasOwnProperty(abbr)) {
@danwill
danwill / _media-queries.scss
Created January 30, 2013 21:53 — forked from anthonyshort/_media-queries.scss
Sass: Media Query Mix-ins #snippet
// Media Queries in Sass 3.2
//
// These mixins make media queries a breeze with Sass.
// The media queries from mobile up until desktop all
// trigger at different points along the way
//
// And important point to remember is that and width
// over the portrait width is considered to be part of the
// landscape width. This allows us to capture widths of devices
// that might not fit the dimensions exactly. This means the break