Thursday, October 13, 2005

Javascript Control Helpers funcitons

Howto call:
setGroup(!this.checked, 'name1,name2,name3,etc')

radioPropertyChanged(this, 'name1,name2,etc')

getControls();

callOnclick('name');

//////////////////////////////////////
/**
* JavaScript functions for enabling / disabling controls
*/

function radioPropertyChanged(control, controlnamestring) {
if (event.propertyName == '' event.propertyName == 'checked') {
setGroup(control.checked, controlnamestring);
}
}

function setGroup(enabled, controlnamestring) {
// alert(controlnamestring + ': ' + enabled);
var controlnames = controlnamestring.split(',');
for (var i=0; i var control = document.getElementById(controlnames[i]);
if (control) {
if (!enabled && 'isvalid' in control)
ValidatorEnable(control, enabled)
else {
control.enabled = enabled;
control.disabled = !enabled;
}
if (!enabled) {
try {
var tagName=control.tagName.toLowerCase();
if(tagName=='input') {
//alert('Found checked in ' + control.id);
var type=control.type.toLowerCase();
if (type=='text') {
control.value='';
if (control.onchange) control.onchange();
}
else if (type=='radio' type=='checkbox'){
control.checked = false;
if (control.onclick) control.onclick();
if (control.onpropertychange) control.onpropertychange();
}
}
else if (tagName=='select') {
// alert('Found selectedIndex in ' + control.id);
control.selectedIndex = -1;
// control.onchange();
}
}
catch(ex){
//ignore
}
}
}
// else alert('control ' + controlname[i] + ' not found!');
}
}

function getControls(){
var ControlsArr = new Array();
ControlsArr = document.forms[0].getElementsByTagName('input');
for(var i=0; i {
if(ControlsArr[i].type == 'checkbox' ControlsArr[i].type == 'radio'){
//alert(ControlsArr[i].id);
callOnclick(ControlsArr[i].id);
}
}
}

function callOnclick(controlName) {
var control = document.all(controlName);
if (control && control.onclick) control.onclick();
else if (control && control.onchange) control.onchange();
else if (control && control.onpropertychange) control.onpropertychange();
}

No comments:

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge