Send this to a friend
1 String.prototype.explode = function(separator:String) {
2 var string = this;
3 var list = new Array();
4
5 if (separator == null) return false;
6 if (string == null) return false;
7
8 var currentStringPosition = 0;
9 while (currentStringPosition<string.length) {
10 var nextIndex = string.indexOf(separator, currentStringPosition);
11 if (nextIndex == -1) break;
12 var word = string.slice(currentStringPosition, nextIndex);
13 list.push(word);
14 currentStringPosition = nextIndex+1;
15 }
16 if (list.length<1) {
17 list.push(string);
18 } else {
19 list.push(string.slice(currentStringPosition, string.length));
20 }
21 return list;
22 }
23
24 var mystring = "test1 - test2";
25 exploded = mystring.explode(" - ");
26 trace (exploded[0]);
String.prototype.explode = function(separator:String) {
var string = this;
var list = new Array();
if (separator == null) return false;
if (string == null) return false;
var currentStringPosition = 0;
while (currentStringPosition<string.length) {
var nextIndex = string.indexOf(separator, currentStringPosition);
if (nextIndex == -1) break;
var word = string.slice(currentStringPosition, nextIndex);
list.push(word);
currentStringPosition = nextIndex+1;
}
if (list.length<1) {
list.push(string);
} else {
list.push(string.slice(currentStringPosition, string.length));
}
return list;
}
var mystring = "test1 - test2";
exploded = mystring.explode(" - ");
trace (exploded[0]);
Send this to a friend
requires prototype and script.aculo.us
demo: http://ajaxorized.com/examples/scriptaculous/email.html
1 var isValid = false;
2
3 validateEmail = function(e) {
4 if(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(e.value)) {
5 if(!isValid) {
6 $(e).morph('border-color:#00FF00', {duration:.3});
7 isValid = true;
8 }
9 } else {
10 if(isValid) {
11 $(e).morph('border-color:#FF0000', {duration:.3});
12 isValid = false;
13 }
14 }
15 }
16
17
var isValid = false;
validateEmail = function(e) {
if(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(e.value)) {
if(!isValid) {
$(e).morph('border-color:#00FF00', {duration:.3});
isValid = true;
}
} else {
if(isValid) {
$(e).morph('border-color:#FF0000', {duration:.3});
isValid = false;
}
}
}
Send this to a friend
1 Event.observe(window, 'load', function() {
2 var fields = $$("input");
3 for (var i = 0; i fields[i].onfocus = function() {this.className += ' focused';}
4 fields[i].onblur = function() {this.className = this.className.replace('focused', '');}
5 }
6 });
7
8
9
10
11
Event.observe(window, 'load', function() {
var fields = $$("input");
for (var i = 0; i fields[i].onfocus = function() {this.className += ' focused';}
fields[i].onblur = function() {this.className = this.className.replace('focused', '');}
}
});
Send this to a friend
a simple listener: $(‘myForm’).observe(‘submit’, validateMyForm) dont support extra params in the function (in the case, validateMyForm. the solution:
1 $('myForm').observe('submit', function(event) {
2 validateMyForm(event, param1, param2);
3 });
$('myForm').observe('submit', function(event) {
validateMyForm(event, param1, param2);
});