03/20/07
sLvalidate v.1
javascripthover edges to scroll
//////////////////////////////////////////////////////////////////////////////////////////////////
/* sLvalidate - v1.0 - 5:16 PM 20/03/2007
@author: kc@slajax.com
@validates entries for sLquantity before posting to update cookie
var sLvalidateOpts = {
items:'select', // boxes to gather
submitBtn: 'button', // id of submit button
valid: true // this must be set to true for validation to occur
};
*/
//////////////////////////////////////////////////////////////////////////////////////////////////
var sLvalidate = new Class({
initialize:function(options){
this.setOptions(options);
this.href(options);
},
setOptions:function(options){
this.options = Object.extend( { }, options || { } );
},
gather:function(options){
this.resetErrors(options);
this.itemArr = [];
this.itemObj = {};
$$(options.items).each(function(el,i){
this.itemArr[i] = $(el).options[$(el).selectedIndex].value;
this.itemObj[i] = $(el);
}.bind(this) );
this.validate(options);
},
validate:function(options){
this.itemArr.each(function(el,i){
if ( this.itemArr[i] == 0 )
this.throwError(options, i);
}.bind(this) );
if( options.valid ) document.forms[0].submit()
},
throwError:function(options, i){
options.valid = false;
this.itemObj[i].getParent().getParent().setStyle('background-color','#FF0000');
this.itemObj[i].getParent().getParent().setStyle('padding','2px 0px 2px 2px');
},
resetErrors:function(options){
options.valid = true;
$$(options.items).each(function(el,i){
$(el).getParent().getParent().setStyle('background-color','#FFFFFF');
$(el).getParent().getParent().setStyle('padding','0');
}.bind(this) );
},
href:function(options){
$(options.submitBtn).addEvent('click', function(){
this.gather(options);
}.bind(this) );
}
});
var sLvalidateOpts = {
items:'select', // boxes to gather
submitBtn: 'button', // id of submit button
valid: true // this must be set to true for validation to occur
};
var validate = new sLvalidate(sLvalidateOpts);
No comments yet.