Forum Moderators: open
Here’s some pseudo script to give a better idea of what I'd like to do...
function showHide()
{
if (field has such and such a value)
{
document.“all showhide classes”.style.visibility = “hidden”;
}
if (field has such and such a value)
{
document.“all showhide classes”.style.visibility = “visible”;
}
}
I realize this script probably looks laughable. And I’m guessing this approach is not possible because the DOM seems based around IDs and Names. But I really have an incomplete knowledge, so I thought I’d ask. Don’t suppose there is any way to access the stylesheet directly to gain this end?
Thanks for the help…
-Jay
function showHide(val){
if (document.styleSheets) {
styleSheet = document.styleSheets[0];
if (styleSheet.cssRules) {
cssRule = styleSheet.cssRules[0];
} else if (styleSheet.rules) {
cssRule = styleSheet.rules[0];
}
if (cssRule) {
cssRule.style.visibility = val;
}
}
}
<input type="checkbox" onchange="showHide(this.checked?'visible':'hidden')" />
(not real sure about the above usage, but I'm sure you'll figure it out)
In both cases, you have a ref to the form element:
var theForm = document.forms["formName"]
1. Brute force
Get the collection of spans in the form, and loop through them, filtering the classNames (not nec. if you have no other spans in there)
[blue]var spans = theForm.getElementsByTagName("span")
for(var k=0;k<spans.length;k++)
if(spans[k].className.toLowerCase()=="thespanclassname")
spans[k].style.visibility = "hidden" // or .display = "none"[/blue]
2. Contextual selector
Say this is your stylesheet
[blue].spanclass
{
... style defs...
}.noasterix .spanclass /* note the space */
{
visibility:hidden;
}[/blue]
The 2nd rule affects class, spanclass when it has an ancestor of class noasterix.
When you want to hide the spans, simply:
[blue]theForm.className = "noasterix"[/blue]
To show them again:
[blue]theForm.className = ""[/blue]
This is assuming your form has no class to start with, as it probably doesn't. The technique is still possible if it does, but it's trickier.