Hi all,
I have a section of a form that looks like this:
I'd like to use javascript to initially hide this section then have a plus sign within the legend to show the fieldset. At the moment I'm having to use a click method on the actual fieldset, but I think I want to be able to run this off the child element <legend>
Here's the code I have so far:
Any ideas how to do this?
Thanks,
R
I have a section of a form that looks like this:
Code:
<fieldset class="hideme" onclick="endhide(this)">
<legend>Properties is less than 5 years old</legend>
<em>If the property is less than 5 years old, please
enter the following</em>
<div>
<label class="left-label" for="developer">Name of developer</label>
<input name="developer" type="text" class="inputbox" id="developer" />
</div>
<div>
<label class="left-label" for="siteName">Site name & phase</label>
<input name="siteName" type="text" class="inputbox" id="siteName" />
</div>
<div>
<label class="left-label" for="SiteRoad">Off site road name</label>
<input name="SiteRoad" type="text" class="inputbox" id="SiteRoad" />
</div>
</fieldset>
I'd like to use javascript to initially hide this section then have a plus sign within the legend to show the fieldset. At the moment I'm having to use a click method on the actual fieldset, but I think I want to be able to run this off the child element <legend>
Here's the code I have so far:
Code:
<style type="text/css" media="all">
@import url(../styles/layout4.css);
fieldset.hideme {}
fieldset.hidemenow {border: none;}
fieldset.hidemenow div,
fieldset.hidemenow em {display: none;}
</style>
<script type="text/javascript">
document.getElementsByClassName = function(clsName){
var retVal = new Array();
var elements = document.getElementsByTagName("*");
for(var i = 0;i < elements.length;i++){
if(elements[i].className.indexOf(" ") >= 0){
var classes = elements[i].className.split(" ");
for(var j = 0;j < classes.length;j++){
if(classes[j] == clsName)
retVal.push(elements[i]);
}
}
else if(elements[i].className == clsName)
retVal.push(elements[i]);
}
return retVal;
}
window.onload = function starthide() {
var hidefield = document.getElementsByClassName('hideme');
for(i = 0; i < hidefield.length; i++) {
hidefield[i].className = "hidemenow";
}
}
function endhide(thefieldset) {
thefieldset.className = "hideme";
}
</script>
Any ideas how to do this?
Thanks,
R