Hi All,
I have a function that I have been working on to dynamically (based on the user's selection in a drop list) enable and destroy spry validation for a couple of text fields (while also showing or hiding these fields). This part is working great but what I would like to do is if the user fills in data for these fields and then changes their mind and makes another selection I would like the fields to be cleared so that the data will not be entered into my database. I have what I think should be a working code but for some reason it's not. Could someone help me figure out what I am overlooking here? I added "this is not working" to my comments where the broken code is.
Thanks in advance,
Ken
I have a function that I have been working on to dynamically (based on the user's selection in a drop list) enable and destroy spry validation for a couple of text fields (while also showing or hiding these fields). This part is working great but what I would like to do is if the user fills in data for these fields and then changes their mind and makes another selection I would like the fields to be cleared so that the data will not be entered into my database. I have what I think should be a working code but for some reason it's not. Could someone help me figure out what I am overlooking here? I added "this is not working" to my comments where the broken code is.
Thanks in advance,
Ken
JavaScript:
// show and hide sections of a form
function preparePage() {
var EquipLoc = document.getElementById("EquipLoc");
var EquipID = document.getElementById("EquipID");
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";
//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;
}
//clear any values from these fields (this isn't working)
if (null !== EquipLoc){
EquipLoc.value="";
}
if (null !== EquipID){
EquipID.value="";
}
} else {
// hide the div
document.getElementById("Equipment").style.display = "none";
document.getElementById("Satellites").style.display = "none";
//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;
}
//clear any values from these fields (this isn't working)
if (null !== EquipLoc){
EquipLoc.value="";
}
if (null !== EquipID){
EquipID.value="";
}
}
};