Jump to content

[SOLVED] Collapsing a span onclick and also changing the image clicked


Darkmatter5

Recommended Posts

Here's the Javascript

function togspan(c_img) {
    if(document[c_img].src.indexOf("images/minus.gif")!= -1) document[c_img].src="images/plus.gif";
    else document[c_img].src="images/minus.gif";
    var notesID=document.getElementById("notes");
    if(notesID.style.display="none") { notesID.style.display="block"; }
    else { notesID.style.display="none"; }
}

 

Here's the CSS

#notes {
    display: none;
}

 

Here's the HTML

<a href="javascript:togspan('img');"><img name="img" src="images/plus.gif" border="0" width="11" height="11" style="float: left;"></a><span class="medium_text">Notes & instructions:
<span id="notes" class="medium_text"><ol>
  <li>All fields marked with a red asterisks denotes a required field.</li>
  <li>Game cover scans you supply are not always used in the final database record.<br>
  If we deem the image of poor quality, etc... we will most likely delete the image<br>
  and aquire one on our own.</li>
</ol></span>

 

The image starts off as "plus.gif" and the span as "display:none;" as expected, and clicking the image changes the image to "minus.gif" and the span does change to "display:block;", but clicking again only toggles the image and doesn't recollapse the span.  Why??

The problem is in the second IF statement where the code is SETTING the value instead of TESTING the value. Need to use a double equal sign.

 

function togspan(c_img) {
    if(document[c_img].src.indexOf("images/minus.gif")!= -1)
    {
        document[c_img].src="images/plus.gif";
        document.getElementById('notes').style.display="none";
    }
    else
    {
        document[c_img].src="images/minus.gif";
        document.getElementById('notes').style.display="block";
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.