...

View Full Version : Validation: Get an unchecked radio group's name?



Opally
06-11-2007, 07:35 PM
Hi.

I did find some threads that are similar to this, but nothing quite answers what I need.

I'm working on validating radio buttons in a form. I want to require that a button be selected from required radio button groups before accepting the submit. Not all the radio button groups are required to have a selection.

One problem I'm having is that I can't return the name of the radio button group. I want to switch case on the name of the radio button group.

I do have an id for each individual radio button, so I can confirm that the for loops are working, but my alert tells me that radiogroups[j] is an [object] and radiogroups[j].name is undefined.

And there is a problem with the logic, too. If just one of the radio button sets is checked, the form validates.

What I've got so far:


function validateFields(){ // these are my required radio button fields
var radiogroups = new Array(
document.forms[0].profile,
document.forms[0].chargetuition,
document.forms[0].speced,
document.forms[0].prek1,
document.forms[0].prek2,
document.forms[0].monitorperf,
document.forms[0].ckpat,
document.forms[0].k8,
document.forms[0].training,
document.forms[0].natconf
);
var radioselected = false;

for (var j = 0; j < radiogroups.length; j++) {
for (var k=0; k < radiogroups[j].length; k++) {
if (radiogroups[j][k].checked == true) {
radioselected = true;
alert(radiogroups[j][k].id + " is checked in group " + radiogroups[j].name);
}// if true
} // for radiobuttons k
if (!radioselected) {
alert(radiogroups[j].name + " has no selection");
var errdisplay = document.getElementById('error_' + radiogroups[j].name);
switch(radiogroups[j]) {
case "profile" :
var errormessage = "New profile or update?";
showError(errormessage, errdisplay)
break;
case "chargetuition" :
var errormessage = "Do you charge tuition?";
showError(errormessage, errdisplay)
break;
case "speced" :
var errormessage = "Are you using Core Knowledge with special needs children?";
showError(errormessage, errdisplay)
break;
case "prek1" :
var errormessage = "Do you use the entire Preschool Sequence with Level 1 classes?";
showError(errormessage, errdisplay)
break;
case "prek2" :
var errormessage = "Do you use the entire Preschool Sequence with Level 2 classes?";
showError(errormessage, errdisplay)
break;
case "monitorperf" :
var errormessage = "Does your school use assessments?";
showError(errormessage, errdisplay)
break;
case "ckpat" :
var errormessage = "Do you use the CK-PAT?";
showError(errormessage, errdisplay)
break;
case "k8" :
var errormessage = "Is your school using Core Knowledge in grades K8?";
showError(errormessage, errdisplay)
break;
case "training" :
var errormessage = "Has your preschool had Core Knowledge Preschool Training?";
showError(errormessage, errdisplay)
errdisplay.appendChild(showerror);
break;
case "natconf" :
var errormessage = "Have you attended a national conference?";
showError(errormessage, errdisplay)
break;
default:
break;
} //switch
return false;
} // if !radioselected

} // for radiogroups j
return true;

}

function showError(message, errdisp) {
var showerror = document.createTextNode(message);
while(errdisp.lastChild) { // remove any childs from errdisplay
errdisp.removeChild(errdisp.firstChild);
}
errdisp.appendChild(showerror);
}

thanks!!!

---Opally

Opally
06-11-2007, 07:48 PM
Also tried radiogroups[j][k].name but got an error saying it was null or not an object.

But if radiogroups[j][k].id correctly returns the id of the element, why doesn't radiogroups[j].name or radiogroups[j][k].name return the name of the element?

I did define radiogroups[j] as an array of radio element names, so I'm befuddled.

The form can be seen here (http://www.coreknowledge.org/secure/html_forms/prekprofile.php).

Opally
06-11-2007, 08:28 PM
Got this working, but the logic is still not right, the form passes on to the review screen if just one radio button group is checked, instead of all.


function validateFields(){

var radiogroups = new Array(
"profile",
"chargetuition",
"speced",
"prek1",
"prek2",
"monitorperf",
"ckpat",
"k8",
"training",
"natconf"
);
var radioselected = false;
var myform = document.prekprofile;
for (var j = 0; j < radiogroups.length; j++) {
for (var k=0; k < myform[radiogroups[j]].length; k++) {
if (myform[radiogroups[j]][k].checked == true) {
radioselected = true;
alert(myform[radiogroups[j]][k].id + " is checked in group " + radiogroups[j]);
}// if true
} // for radiobuttons k
if (!radioselected) {
alert(radiogroups[j] + " has no selection");
var errdisplay = document.getElementById('error_' + radiogroups[j]);
switch(radiogroups[j]) {
case "profile" :
var errormessage = "New profile or update?";
showError(errormessage, errdisplay)
break;
case "chargetuition" :
var errormessage = "Do you charge tuition?";
showError(errormessage, errdisplay)
break;
case "speced" :
var errormessage = "Are you using Core Knowledge with special needs children?";
showError(errormessage, errdisplay)
break;
case "prek1" :
var errormessage = "Do you use the entire Preschool Sequence with Level 1 classes?";
showError(errormessage, errdisplay)
break;
case "prek2" :
var errormessage = "Do you use the entire Preschool Sequence with Level 2 classes?";
showError(errormessage, errdisplay)
break;
case "monitorperf" :
var errormessage = "Does your school use assessments?";
showError(errormessage, errdisplay)
break;
case "ckpat" :
var errormessage = "Do you use the CK-PAT?";
showError(errormessage, errdisplay)
break;
case "k8" :
var errormessage = "Is your school using Core Knowledge in grades K8?";
showError(errormessage, errdisplay)
break;
case "training" :
var errormessage = "Has your preschool had Core Knowledge Preschool Training?";
showError(errormessage, errdisplay)
errdisplay.appendChild(showerror);
break;
case "natconf" :
var errormessage = "Have you attended a national conference?";
showError(errormessage, errdisplay)
break;
default:
break;
} //switch
return false;
} // if !radioselected

} // for radiogroups j
return true;

}

function showError(message, errdisp) {
var showerror = document.createTextNode(message);
while(errdisp.lastChild) { // remove any childs from errdisplay
errdisp.removeChild(errdisp.firstChild);
}
errdisp.appendChild(showerror);
}

Opally
06-11-2007, 09:03 PM
I figure I need to add a counter, to count whether all the radiobutton groups have selections, and when they do, it's valid.

Is there a technique to return a "focus" to a radio button group? Embed named anchors and... how do I call the page with the named anchor appended, hmm.

So far, my error message is displaying in its span, but it displays even if the radio button is selected, so I still have a logic problem... still thinking about this...


function validateFields(){

var radiogroups = new Array(
"profile",
"chargetuition",
"speced",
"prek1",
"prek2",
"monitorperf",
"ckpat",
"k8",
"training",
"natconf"
);
var radioallselected = 0;
var radiovalid = false;
var myform = document.prekprofile;
for (var j = 0; j < radiogroups.length; j++) {
for (var k=0; k < myform[radiogroups[j]].length; k++) {
if (myform[radiogroups[j]][k].checked == true) {
radioallselected++;
alert(myform[radiogroups[j]][k].id + " is checked in group " + radiogroups[j] + "\n\nradioallselected = " + radioallselected);
}// if true
} // for radiobuttons k
radiovalid = (radioallselected == radiogroups.length ? true : false);
if (radiovalid) {
break;
} else if (!radiovalid) {
alert(radiogroups[j] + " has no selection");
var errdisplay = document.getElementById('error_' + radiogroups[j]);
switch(radiogroups[j]) {
case "profile" :
var errormessage = "New profile or update?";
showError(errormessage, errdisplay);
break;
case "chargetuition" :
var errormessage = "Do you charge tuition?";
showError(errormessage, errdisplay)
break;
case "speced" :
var errormessage = "Are you using Core Knowledge with special needs children?";
showError(errormessage, errdisplay)
break;
case "prek1" :
var errormessage = "Do you use the entire Preschool Sequence with Level 1 classes?";
showError(errormessage, errdisplay)
break;
case "prek2" :
var errormessage = "Do you use the entire Preschool Sequence with Level 2 classes?";
showError(errormessage, errdisplay)
break;
case "monitorperf" :
var errormessage = "Does your school use assessments?";
showError(errormessage, errdisplay)
break;
case "ckpat" :
var errormessage = "Do you use the CK-PAT?";
showError(errormessage, errdisplay)
break;
case "k8" :
var errormessage = "Is your school using Core Knowledge in grades K8?";
showError(errormessage, errdisplay)
break;
case "training" :
var errormessage = "Has your preschool had Core Knowledge Preschool Training?";
showError(errormessage, errdisplay)
errdisplay.appendChild(showerror);
break;
case "natconf" :
var errormessage = "Have you attended a national conference?";
showError(errormessage, errdisplay)
break;
default:
break;
} //switch
return false;
} // if !radioselected

} // for radiogroups j
return true;

}

function showError(message, errdisp) {
var showerror = document.createTextNode(message);
while(errdisp.lastChild) { // remove any childs from errdisplay
errdisp.removeChild(errdisp.firstChild);
}
errdisp.appendChild(showerror);
}

glenngv
06-11-2007, 09:22 PM
how do I call the page with the named anchor appended, hmm.


location.hash = "#anchorName";



So far, my error message is displaying in its span, but it displays even if the radio button is selected, so I still have a logic problem... still thinking about this...

It's because you are not setting the corresponding error span to empty. Previous error msg might be in the span so you need to always set it to empty when radio button selection is valid.



if (radiovalid) {
//reset corresponding error here
break;
} else if (!radiovalid) {
...
}

Opally
06-11-2007, 09:53 PM
thanks for the help, Glenn!! I will incorporate your suggestions.

I have another problem with the script so far: I don't believe it's seeing the length of the radio button array. It only evaluates correctly if the first radio button in the set is checked, the second radio button is invisible.

Specifically, myform[radiogroups[j]].length is not evaluating the number of radio buttons in the group.

What I've got so far, with a counter to check how many radio button groups are valid:


function validateFields(){


var radiogroups = new Array(
"profile",
"chargetuition",
"speced",
"monitorperf",
"prek1",
"prek2",
"ckpat",
"k8",
"training",
"natconf"
);
var radioallselected = 0;
var radiovalid = false;
var myform = document.prekprofile;
for (var j = 0; j < radiogroups.length; j++) {
for (var k=0; k < myform[radiogroups[j]].length; k++) {
if (myform[radiogroups[j]][k].checked == true) {
radioallselected++;
alert(myform[radiogroups[j]][k].id + " is checked in group " + radiogroups[j] + "\n\nradioallselected = " + radioallselected);
}// if true
if (radioallselected == j) { // no buttons selected in j
alert(radiogroups[j] + " has no selection");
var errdisplay = document.getElementById('error_' + radiogroups[j]);
switch(radiogroups[j]) {
case "profile" :
var errormessage = "New profile or update?";
showError(errormessage, errdisplay);
break;
case "chargetuition" :
var errormessage = "Do you charge tuition?";
showError(errormessage, errdisplay)
break;
case "speced" :
var errormessage = "Are you using Core Knowledge with special needs children?";
showError(errormessage, errdisplay)
break;
case "monitorperf" :
var errormessage = "Does your school use assessments?";
showError(errormessage, errdisplay)
break;
case "prek1" :
var errormessage = "Do you use the entire Preschool Sequence with Level 1 classes?";
showError(errormessage, errdisplay)
break;
case "prek2" :
var errormessage = "Do you use the entire Preschool Sequence with Level 2 classes?";
showError(errormessage, errdisplay)
break;
case "ckpat" :
var errormessage = "Do you use the CK-PAT?";
showError(errormessage, errdisplay)
break;
case "k8" :
var errormessage = "Is your school using Core Knowledge in grades K8?";
showError(errormessage, errdisplay)
break;
case "training" :
var errormessage = "Has your preschool had Core Knowledge Preschool Training?";
showError(errormessage, errdisplay)
errdisplay.appendChild(showerror);
break;
case "natconf" :
var errormessage = "Have you attended a national conference?";
showError(errormessage, errdisplay)
break;
default:
break;
} //switch
return false;
} // no buttons selected in j
} // for radiobuttons k
radiovalid = (radioallselected == radiogroups.length ? true : false);
if (radiovalid) {
break;
} else continue ;
} // for radiogroups j

return true;

}

function showError(message, errdisp) {
var showerror = document.createTextNode(message);
while(errdisp.lastChild) { // remove any childs from errdisplay
errdisp.removeChild(errdisp.firstChild);
}
errdisp.appendChild(showerror);
}

form is here (http://www.coreknowledge.org/secure/html_forms/prekprofile.php).

---Opally

Opally
06-11-2007, 10:26 PM
kewl, this ALMOST does what I want it to. Thank you for the anchor focus and look how I dealt with cleaning up the error message: nothing like recycling!

Except I am not getting the .length of the radio button element.

for (var k=0; k < myform[radiogroups[j]].length; k++) {


function validateFields(){

var radiogroups = new Array(
"profile",
"chargetuition",
"speced",
"monitorperf",
"prek1",
"prek2",
"ckpat",
"k8",
"training",
"natconf"
);
var radioallselected = 0;
var radiovalid = false;
var myform = document.prekprofile;
for (var j = 0; j < radiogroups.length; j++) {
for (var k=0; k < myform[radiogroups[j]].length; k++) {
var errdisplay = document.getElementById('error_' + radiogroups[j]);
if (myform[radiogroups[j]][k].checked == true) {
radioallselected++;
alert(myform[radiogroups[j]][k].id + " is checked in group " + radiogroups[j] + "\n\nradioallselected = " + radioallselected);
showError('',errdisplay);
}// if true
if (radioallselected == j) { // no buttons selected in j
alert(radiogroups[j] + " has no selection");
var anchorname = "#" + radiogroups[j] + "anchor";
switch(radiogroups[j]) {
case "profile" :
var errormessage = "New profile or update?";
showError(errormessage, errdisplay);
location.hash = anchorname;
break;
case "chargetuition" :
var errormessage = "Do you charge tuition?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "speced" :
var errormessage = "Are you using Core Knowledge with special needs children?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "monitorperf" :
var errormessage = "Does your school use assessments?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "prek1" :
var errormessage = "Do you use the entire Preschool Sequence with Level 1 classes?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "prek2" :
var errormessage = "Do you use the entire Preschool Sequence with Level 2 classes?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "ckpat" :
var errormessage = "Do you use the CK-PAT?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "k8" :
var errormessage = "Is your school using Core Knowledge in grades K8?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "training" :
var errormessage = "Has your preschool had Core Knowledge Preschool Training?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "natconf" :
var errormessage = "Have you attended a national conference?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
default:
break;
} //switch
return false;
} // no buttons selected in j
} // for radiobuttons k
radiovalid = (radioallselected == radiogroups.length ? true : false);
if (radiovalid) { // reset error mesages

break;
} else continue ;
} // for radiogroups j

return true;

}

function showError(message, errdisp) {
var showerror = document.createTextNode(message);
while(errdisp.lastChild) { // remove any childs from errdisplay
errdisp.removeChild(errdisp.firstChild);
}
errdisp.appendChild(showerror);
}

glenngv
06-12-2007, 06:45 AM
What does myform[radiogroups[j]].length say if you alert it?

Try changing it to:

myform.elements[radiogroups[j]].length

Opally
06-12-2007, 02:43 PM
Thanks, Glenn.

That suggestion works: myform.elements[radiogroups[j]].length does return the correct length of the radio button group.

However, the loop is still not evaluating if the second radio button is checked. :confused:

It only evaluates myform.elements[radiogroups[j]][k].checked == true if the first button is checked, not the second.

I put in some more diagnostic alerts but still haven't figured it out.


function validateFields(){

var radiogroups = new Array(
"profile",
"chargetuition",
"speced",
"monitorperf",
"ckpat",
"prek1",
"prek2",
"k8",
"training",
"natconf"
);
var radioallselected = 0;
var radiovalid = false;
var myform = document.prekprofile;
for (var j = 0; j < radiogroups.length; j++) {
for (var k=0; k < myform.elements[radiogroups[j]].length; k++) {
var errdisplay = document.getElementById('error_' + radiogroups[j]);
alert("myform.elements[radiogroups[j]].length = " + myform.elements[radiogroups[j]].length + "\n\n k = " + k);
if (myform.elements[radiogroups[j]][k].checked) {
radioallselected++;
alert(myform[radiogroups[j]][k].id + " is checked in group " + radiogroups[j] + "\n\nradioallselected = " + radioallselected);
showError('',errdisplay);
}// if true
if (radioallselected == j) { // no buttons selected in j
alert("radioallselected = " + radioallselected + "\n\n j = " + j);
alert(radiogroups[j] + " has no selection");
var anchorname = "#" + radiogroups[j] + "anchor";
switch(radiogroups[j]) {
case "profile" :
var errormessage = "New profile or update?";
showError(errormessage, errdisplay);
location.hash = anchorname;
break;
case "chargetuition" :
var errormessage = "Do you charge tuition?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "speced" :
var errormessage = "Are you using Core Knowledge with special needs children?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "monitorperf" :
var errormessage = "Does your school use assessments?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "ckpat" :
var errormessage = "Do you use the CK-PAT?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "prek1" :
var errormessage = "Do you use the entire Preschool Sequence with Level 1 classes?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "prek2" :
var errormessage = "Do you use the entire Preschool Sequence with Level 2 classes?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "k8" :
var errormessage = "Is your school using Core Knowledge in grades K8?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "training" :
var errormessage = "Has your preschool had Core Knowledge Preschool Training?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "natconf" :
var errormessage = "Have you attended a national conference?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
default:
break;
} //switch
return false;
} // no buttons selected in j
} // for radiobuttons k
radiovalid = (radioallselected == radiogroups.length ? true : false);
if (radiovalid) { // reset error mesages

break;
} else continue ;
} // for radiogroups j

return true;

}

function showError(message, errdisp) {
var showerror = document.createTextNode(message);
while(errdisp.lastChild) { // remove any childs from errdisplay
errdisp.removeChild(errdisp.firstChild);
}
errdisp.appendChild(showerror);
}

Opally
06-12-2007, 02:51 PM
hmm, it *is* a loop logic problem... will see if I can sort it out...

---Opally

Opally
06-12-2007, 04:15 PM
I think I got it! I had to move the closing bracket of the innermost loop up so it was correctly testing all the radio button conditions before testing whether there was no selection.

THANK YOU for all your SPLENDID help!!!

---Opally


function validateFields(){
var radiogroups = new Array(
"profile",
"chargetuition",
"speced",
"monitorperf",
"ckpat",
"seq",
"k8",
"training",
"natconf"
);
var radioallselected = 0;
var radiovalid = false;
var myform = document.prekprofile;
for (var j = 0; j < radiogroups.length; j++) {
for (var k=0; k < myform.elements[radiogroups[j]].length; k++) {
var errdisplay = document.getElementById('error_' + radiogroups[j]);
// alert("myform.elements[radiogroups[j]].length = " + myform.elements[radiogroups[j]].length + "\n\n k = " + k);
if (myform.elements[radiogroups[j]][k].checked) {
radioallselected++;
// alert(myform[radiogroups[j]][k].id + " is checked in group " + radiogroups[j] + "\n\nradioallselected = " + radioallselected);
showError('',errdisplay);
}// if true
} // for radiobuttons k
if (radioallselected == j) { // no buttons selected in j
// alert("radioallselected = " + radioallselected + "\n\n j = " + j);
// alert(radiogroups[j] + " has no selection");
var anchorname = "#" + radiogroups[j] + "anchor";
switch(radiogroups[j]) {
case "profile" :
var errormessage = "New profile or update?";
showError(errormessage, errdisplay);
location.hash = anchorname;
break;
case "chargetuition" :
var errormessage = "Do you charge tuition?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "speced" :
var errormessage = "Are you using Core Knowledge with special needs children?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "monitorperf" :
var errormessage = "Does your school use assessments?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "ckpat" :
var errormessage = "Do you use the CK-PAT?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "seq" :
var errormessage = "Do you use the entire Preschool Sequence?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "k8" :
var errormessage = "Is your school using Core Knowledge in grades K8?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "training" :
var errormessage = "Has your preschool had Core Knowledge Preschool Training?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
case "natconf" :
var errormessage = "Have you attended a national conference?";
showError(errormessage, errdisplay)
location.hash = anchorname;
break;
default:
break;
} //switch
return false;
} // no buttons selected in j
radiovalid = (radioallselected == radiogroups.length ? true : false);
if (radiovalid) { // reset error mesages

break;
} else continue ;
} // for radiogroups j

return true;

}

function showError(message, errdisp) {
var showerror = document.createTextNode(message);
while(errdisp.lastChild) { // remove any childs from errdisplay
errdisp.removeChild(errdisp.firstChild);
}
errdisp.appendChild(showerror);
}

Opally
06-12-2007, 05:44 PM
oops... having a problem with showHideOnload() function.

I had a small modification, a simplification of my form, and I thought this should be working fine... but no divs are being hidden on page reload. The initial load works correctly, and the selection of the buttons works, but reload of the page after review displays all divs.

The alert is telling me that radGroup is an [object] and doesn't seem to be evaluating.

There is one div, "seqomit", which displays if radio group name="sequence" "no" is selected. All the others display if "yes" is selected for their respective radio buttons.


function showHideOnload(choiceName, divId) {
var frm = document.forms[0];
var radGroup = frm.elements[choiceName];
var choice = getSelectedRadio(radGroup);
alert("radGroup = " + radGroup + " choiceName = " + choiceName + "\n\n divID = " + divId);
if (choiceName.indexOf("sequence")!= -1){
if (!choice || choice.value=="yes") {
document.getElementById(divId).style.display = 'none';
}
else if (choice.value=="no"){
document.getElementById(divId).style.display = 'inline';
}

}
else {
document.getElementById(divId).style.display = (choice) ? 'inline':'none';
}
}


function getSelectedRadio(radGroup){
for (var i=0; i<radGroup.length; i++){
if (radGroup[i].checked) return radGroup[i];
}
return null; //nothing selected
}

function initDivs(){
var arr = new Array(
['sequence', 'seqomit'],
['monitorperf','assmtsfields'],
['ckpat','ckpathowlong'],
['k8','ckgrades'],
['training','modules'],
['natconf', 'natconfyears'] //no comma at the last element
);

for (var i=0; i<arr.length; i++){
showHideOnload(arr[i][0], arr[i][1]);
}
}

glenngv
06-12-2007, 06:10 PM
Is the link to the form you posted in post#2 updated? I tried it there and I saw that when I select yes on some of the radio buttons, the corresponding div is displayed. And when I reload the page, the form is reset, no radio button is selected by default and no divs are displayed.

Opally
06-12-2007, 06:48 PM
Glenn,

Thanks for following up!!

Please try filling out the form and submitting, to set the session. Then return to the form (choose "edit your information" at the review screen.) When the restored form loads, all the divs show. That's the reload condition, you'll see the alerts.

this is the form (http://www.coreknowledge.org/secure/html_forms/prekprofile.php)

What's odd is, I thought this actually was working. I only made a simplification of the previous prek1/prek2 logic, if you remember that. Now it's just a radio button group name="sequence" that, unlike the others, if "yes" is chosen, hides the div. All the others in the array for initDivs work the other way.

whatcha think?

---Opally

glenngv
06-12-2007, 08:59 PM
Change this:

else {
document.getElementById(divId).style.display = (choice) ? 'inline':'none';
}
to:

else {
document.getElementById(divId).style.display = (choice && choice.value=="yes") ? 'inline':'none';
}As far as I can remember, that's what I did when I initially posted that showHideOnload function. You may want to change 'inline' to 'block' as div is a block element not inline.

Opally
06-12-2007, 09:23 PM
SMOOOOOCH!

:thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup:

you are a dream! Thank you so much. Works like a charm.

I did a previous form that was somewhat similar to this, hiding/showing div depending on a selection (from one group of radio buttons, was easier!) and display : inline was the correct style to use, to force it to display, as I recall, display:block did not overwrite display:none.

Adios!

---Opally

glenngv
06-12-2007, 09:31 PM
Glad to be of help to you. :)

Regarding the display property, I haven't encountered any problem changing it from none to block and vice-versa. You can also set the display to "" and the element will be displayed.

Opally
06-13-2007, 03:03 PM
You're right, display:block works great, in fact, it works better than display:inline for my purposes, because I have some styles indenting those divs which only apply to block elements.

:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum