Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

    Need Help: OnMOuse Over and multiple instances

    Hello all, I am very inexperienced in writing javascript, but need to get a few things to work. I'm doing 2 thing with js right now using code that is only partially mine to begin with.

    1) A swap image. This work fine, but I need a third 'onMouseOver' option to add to this.

    2)The action of this image (a button). I have it so that it expands a section of a page to reveal more content. This works fine as well, but I need to have more than one instance on the page. I'm pretty sure the problem is with the id, but can't get it to work if I place the html code more than once.

    I apologize for the novice level of this. I should know how to do this, but I don't. The page itself is not live, so I can't show anything in action. Help would be great appreciated. I've listed the js and the html I have below.
    <script language=JavaScript>
    intImage = 2;
    function swapImage() {
    switch (intImage) {
     case 1:
       IMG1.src = "images/expander-img1.jpg"
       intImage = 2
    case 2:
       IMG1.src = "images/expander-img2.jpg"
       intImage = 1
    <script language="JavaScript" type="text/javascript">
    if (document.getElementById) {
    document.writeln('<style type="text/css"><!--')
    document.writeln('.texter {display:none} @media print {.texter {display:block;}}')
    document.writeln('//--></style>') }
    function openClose(theID) {
    if (document.getElementById(theID).style.display == "block") { document.getElementById(theID).style.display = "none" }
    else { document.getElementById(theID).style.display = "block" } }
    <div onClick="openClose('a1')" style="cursor:hand; cursor:pointer"><div class="centered"><IMG id="IMG1" name="IMG1" src="images/expander-img1.jpg" onclick="swapImage();"></div>
    <div id="a1" class="texter"> (content)</div>

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Thanked 1,013 Times in 1,010 Posts
    Double post. Answered in the other one http://www.codingforums.com/showthre...28#post1358328
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts