Hi,
I have a toggle function that works brilliantly
[code]
// Toggle
function toggleDiv(elementshow, element, elementhide, elementhide2, elementhide3){
var els;
var newDisplay;
elh = document.getElementById(elementhide);
// if the elh does not exist then hide the show one otherwise show and hide the relative ones
if (elh) {
els = document.getElementById(elementshow);
elh2 = document.getElementById(elementhide2);
elh3 = document.getElementById(elementhide3);
if (els.style.display != ‘block’) {
els.style.display = ‘block’;
}
if(elh.style.display != ‘none’) {
elh.style.display = ‘none’;
}
if ((elh2) && (elh2.style.display != ‘none’)) {
elh2.style.display = ‘none’;
}
if ((elh3) && (elh3.style.display != ‘none’)) {
elh3.style.display = ‘none’;
}
} else {
// Get the elements that have the tag of els
var allelements = getElementsByClass(elementshow, null, element);
for(var i = 0; i < allelements.length; i++) {
if (allelements[i].style.display != ‘block’) {
allelements[i].style.display = ‘block’;
} else {
allelements[i].style.display = ‘none’;
}
}
}
}
This works without a problem and I will run it like so
[code]
onclick=”toggleDiv(‘gal’,null,’img’);”
What I am trying to do this is run it without the onclick from within a javascript function
I basicly have this function
[code]
// Trigger onclick
function triggerOnClick(inputName, inputValue) {
toggleDiv(‘gal’,null,’img’);
}
As you can see at the moment I am just trying to run that togglediv function.
Problem is it is not correctly running it? Nothing happens when the page loads.
I am running it like so
[code]
<script language=”javascript” type=”text/javascript”>
triggerOnClick();
</script>
Why is the toggle not correctly working but it is when I click on it?
Thanks
k0r54