...

View Full Version : Setting and unsetting variables



MaDmiX
05-22-2012, 03:30 AM
Hi All,

I would like to enable / disable my field validation based upon the status of a given checkbox in my form but I am unsure about how to "unset" the varibles that control the validation. If the user clicks the checkbox, this displays the fields ant enables my validation just fine. But if the user then unckeck the box, the field is hidden but the validation remains enabled and the form cannot be submitted. Here is my code:


if (document.getElementById("OnAirVariance").checked) {
var sprytextfield3 = new Spry.Widget.ValidationTextField("spryStartTime", "time", {validateOn:["blur"], format:"HH:mm:ss", useCharacterMasking:true});
var sprytextfield4 = new Spry.Widget.ValidationTextField("spryEndTime", "time", {format:"HH:mm:ss", useCharacterMasking:true, validateOn:["blur"]});
var sprytextfield5 = new Spry.Widget.ValidationTextField("spryMaterialID", "none", {validateOn:["blur"]});
var sprytextfield6 = new Spry.Widget.ValidationTextField("spryTitle", "none", {validateOn:["blur"]});
}else{
I NEED TO BE ABLE TO REVERSE THE SET VARIABLES SO THE VALIDATION WILL NOT STAY IN EFFCT
}

Thanks in advance for any help.

Kind regards,

Ken

MaDmiX
05-23-2012, 08:20 PM
Nevermind. Got it sorted. If anyone is interested, this may be helpful:


function preparePage() {

document.getElementById("List1").onclick = function() {
if (document.getElementById("List1").value=="Equipment issue") {
// use CSS style to show it
document.getElementById("Equipment").style.display = "block";
document.getElementById("Satellites").style.display = "none";

// if there isn't a validaton, build one
if(!sprytextfield2){
sprytextfield2 = new Spry.Widget.ValidationTextField("spryEquipID", "none", {validateOn:["blur"]});
}
if(!spryselect1){
spryselect1 = new Spry.Widget.ValidationSelect("spryEquipLoc", {validateOn:["blur"]});
}

} else if (document.getElementById("List1").value=="Satellite issue") {
// use CSS style to show it
document.getElementById("Satellites").style.display = "block";
document.getElementById("Equipment").style.display = "none";

//clear any values from these fields
document.getElementById("EquipLoc").value=null
document.getElementById("EquipID").value=null

//if exists, destroy spry field validation for these fields
if (sprytextfield2) {
sprytextfield2.resetClasses();
sprytextfield2.destroy();
sprytextfield2 = null;
}

if (spryselect1) {
spryselect1.resetClasses();
spryselect1.destroy();
spryselect1 = null;
}

} else {
// hide the div
document.getElementById("Equipment").style.display = "none";
document.getElementById("Satellites").style.display = "none";

//clear any values from these fields
document.getElementById("EquipLoc").value=null
document.getElementById("EquipID").value=null

//if exists, destroy spry field validation for these fields
if (sprytextfield2) {
sprytextfield2.resetClasses();
sprytextfield2.destroy();
sprytextfield2 = null;
}

if (spryselect1) {
spryselect1.resetClasses();
spryselect1.destroy();
spryselect1 = null;
}

}
};

Kind regards,

Ken



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum