Javascript Code Snippets

David Carr

format a number in a money format by adding commas into the number.

Read more

Recursivepaiste

A handy function to detect the presence of an item in an array.

Read more

David Carr

Sum multiple fields together that have the same class, add the total value to an input.

Read more

Recursivepaiste

This snippet will detect when a user has stopped typing in an input element of a form, and then, as a result, it will call a function. Ideal for making form calculations on the fly in real-time.

See this answer for more detail:

http://stackoverflow.com/a/5926782

Read more

David Carr

Using select2 https://select2.github.io/examples.html to create a select menu that can be searched to populate the results with an ajax request.

Read more

David Carr

Use a ajax to remove an element from a page useful when listing tabular data and a row needs to be removed.

The row has a class of record jQuery will use that to remove the row from the page. The element has an id attribute which will hold the id of the record (when coming from a database) optionally more information can be passed using data attributes in this case a data-name which is a custom name of the item to be removed.

Read more

David Carr

submit form via ajax, the method, url are taken from the form.

Read more

David Carr

with two divs with id's of #from and #to copy the date from the #from div into the #to div adding an hour to the time for the #to div.

Read more

Copyright © 2017 created by David Carr Web Developer. All code MIT license. All rights reserved. Built using Simple MVC Framework