Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2003
    Location
    Gothenburg, Sweden
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing var on mouseOver?

    I think this might be a silly question but I'm really stuck.

    I want to change a variable with javascript on a mouseOver-script. This is what I've done:


    First I made a script at the beginning of the page, stating the variables and arrays:

    <script language="JavaScript">
    <!--
    var showNum = 2;
    var tom = new Array('')
    var ingemar = new Array('<span class="ingress">Namn:</span> Ingemar Någonting<br><span class="ingress">Uppgifter:</span> Översättning<br>');

    var infoText = new Array(tom,ingemar);
    -->
    </script>



    Further down on the page I'm writing out the Array, depending on the variable showNum, in a <TD>:

    <td ID="textTD" class="brodtext" valign="top" width="529">
    <script language="javascript">
    document.write(infoText[showNum])
    </script>
    </td>


    To that point everything is working out just fine! But what I want to do next is to change which text-Array-content that will show, using a mouseOver-script on a image.

    (this is how I've tried; onMouseOver=parent.infoText.value=4)

    Is this possible? Can I change that text-Array to show another content without refreshing the page?

    I would be deeply thankfull to anyone who can help me!

    /Xoom

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    You... kind of can, but not the way you're doing it. This bit:

    <script language="javascript">
    document.write(infoText[showNum])
    </script>

    ... is only going to happen once, when the page loads. What you want is a html block that you can get hold of, and edit its content on the fly. Like a <div>. What you also need is a function that's going to do the getting hold of and the editing:

    function contentSwap(contentNumber){
    document.textDIV.innerHTML=infoText[contentNumber])
    }


    ... that you can call with:

    <div id = "textDIV" onMouseOver="contentSwap(1)">


    ... which is a bit inelegant but it'll work, in IE at least.

    Does that make any sense?

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    If I may just add this, it might make it a little more clearer





    <script language="JavaScript">
    <!--
    var ingemar = new Array("First Index","Second Index","Third Index");
    function contentSwap(contentNumber){
    textDIV.innerHTML=ingemar[contentNumber]
    }

    -->
    </script>

    <a href="#null" onMouseOver="contentSwap(0)">Mouse Me 1</a> <BR>
    <a href="#null" onMouseOver="contentSwap(1)">Mouse Me 2</a><BR>
    <a href="#null" onMouseOver="contentSwap(2)">Mouse Me 3</a>

    <P><div id = "textDIV">Content</div>

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    what he said....

  • #5
    New Coder
    Join Date
    Jun 2003
    Location
    Gothenburg, Sweden
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks!

    Thank you very much for your professional help!

    I guess this will be working after I've done it right. Just one more question:

    If my Array contains variables then I don't need the ""?
    like:

    var tom = new Array('String')
    var ingemar = new Array('String')
    var infoText = new Array(tom,ingemar)

    Right?

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Right


  •  

    Posting Permissions

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