Tuesday, September 1, 2009

Ajax Upload

Impossible! But it looks like it for the end user.

That's right, it is NOT possible to upload files via Ajax. However, it's possible to come pretty close, and with this site, you can get a good looking upload button that looks like web 2.0.
Take a look at Andrew Valum's ajax upload page

For JQuery users: View this demo
(use this JS file:  ajaxupload.3.6.js (at the time of this writing) found in the source of the jquery demo page)

 





Number Only in text fields

Using javascript you can set fields to accept certain characters only using Regex strings. In the following I put the "_decimalonly" class to my text inputs, and with JQuery, when the page is loaded, all the inputs with the "_decimalonly" have the validations implemented.


Here are a few I use for inputs:


Variables for on keypress validation
var decimal = new RegExp("[-|0-9|\.]+");//decimal
var monetary = new RegExp("[0-9|\.]+");//monetary

var integer = new RegExp("[0-9]+");//positive integer
var neginteger= new RegExp("[-|0-9]+");//negative integer

Variables for on blur (submit also) validation
var decimalb = new RegExp("^-?[0-9]*\.?[0-9]{1,}?$");//decimal
var monetaryb = new RegExp("^[0-9]*\.?[0-9]{1,}?$");//monetary
var integerb = new RegExp("^[0-9]*$");//integer
var negintegerb = new RegExp("^-?[0-9]*$");//negative integer

Examples: