Archive for October 31st, 2007
verify blank string on form with javascript
Here’s the function
function isSpaceOnly(s){
var l = s.length;
var c; for(i = 0; i < l; i++){
if(s.charAt(i) != ' ' && s.charAt(i) != '\t' && s.charAt(i) != '\n'){
return false;
}
}
return true;
}
Then you only need to use if that function return true -> meaning blank string including space only string given
create “select all” & “deselect all” for checkbox option with javascript
Sometimes we create HTML document that contains some checkbox option.Sometime we need to click every checkbox option, so is there quick way for doing this? Off course we can do it easily if there’s “select all” button to click every checkbox option…, so how to do it?
Here’s the example code for doing this
function checkAll(){
var i = document.f['keycode_id[]'].length;
if(i == undefined){
document.f['keycode_id[]'].checked = true;
}else{
for(j = 0; j < i; j++){
document.f['keycode_id[]'][j].checked = true;
}
}
}
function unCheckAll(){
var i = document.f['keycode_id[]'].length;
if(i == undefined){
document.f['keycode_id[]'].checked = false;
}else{
for(j = 0; j < i; j++){
document.f['keycode_id[]'][j].checked = false;
}
}
}
With assumption that the document form is “f” and the option chekbox variable name is “keycode_id[]“, otherwise you only need to change it. Next step youonly need to create button with event “onClick” will execute one of those 2 function (select all or deselect all)