...

View Full Version : Changing var on mouseOver?



Xoom
06-09-2003, 06:22 AM
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

Spudhead
06-09-2003, 01:22 PM
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?

Mr J
06-09-2003, 04:38 PM
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>

Spudhead
06-09-2003, 05:32 PM
:thumbsup: what he said....

Xoom
06-09-2003, 11:10 PM
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?

Mr J
06-09-2003, 11:20 PM
Right



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum