PDA

View Full Version : Help with javascript code please


robbiez
07-16-2008, 03:17 PM
Included in the shopping cart software I use is the following function:


function idShowHide(obj) {

var el = document.getElementById(obj);
if ( el.style.display != "none" ) {
el.style.display = 'none';
} else {
el.style.display = 'block';
}
}


The function creates a Show/Hide link for many items within the admin side of the site.
The problem is the default is always SHOW.

Does anybody know how I can change the default to HIDE, or even better for the function to remember the last setting from the last visit.

Thanks in advance
Rob

abduraooft
07-16-2008, 03:27 PM
You could do it simply be adding a style="display:none;" to your element. But this element won't get displayed if there is no javascript support. So you could call a javascript code in the onload even of the page, say
<script type="text/javascript">
window.onload=function(){
document.getElementById('id_of_element').style.display='none';
}
</script>

robbiez
07-16-2008, 04:06 PM
Hi

Many thanks. This has worked as it should do.

However how do I get it to activate more than one element ID?? I have tried comma seperated versions and even seperate Scripts but I can only get it to work on one slement ID.

I thought it would be something like this:
<script type="text/javascript">
window.onload=function(){
document.getElementById('id_of_element','id_of_element2','id_of_element3').style.display='none';
}
</script>



Thanks again
Rob

robbiez
07-16-2008, 04:13 PM
Hi
I have persisted and got it to work like this

<script type="text/javascript">
window.onload=function(){
document.getElementById('gbu0--manageprod--pricingtypeselection--d').style.display='none';
document.getElementById('gbu0--manageprod--pricespecificfields--d').style.display='none';
}

</script>

Thanks Again

ohgod
07-16-2008, 08:13 PM
you could use css if you're going to be applying that in a number of places