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??

Link to comment
Share on other sites

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";
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.