PDA

View Full Version : swapping variables...


Fou-Lu
12-17-2003, 01:06 AM
methinks that would be the best title for this. I'm having great difficulty in changing variables, more specifically array values. Lets see... how to make such a complicated thing easy to explain.
Ok, so we have ourselves a page, and in that page is an iframe. On this page is say... the number one. Click on the number one, and the iframe goes to a list of numbers. These are all onMouseover and onclicks, I refuse to use a select menu for this BTW. Now, when you onMouseOver one of the numbers, a different box will show the change in the value, lets say we are adding. So the one, becomes a two if over another one. Fine and dandy, that was a cinch. Onclick, I want to change the number from the one to the new number, the two. Good, no problems there. This is where the problem comes: when I go to do it again on the new number, the variable has not changed, so it still considers the default value as the selected value.

Yeah, so that was still tougher than I wanted it to be.
On my main page, I would have something like:

<span id="setnum" class="setnum" name="setnum">1</span>
<!--And further down...-->
<span id="viewchng" class="viewchng" name="viewchng">1</span>

The main page has no set javascript for these purposes. Now, in the iframe window, something like:

<span onMouseOver="changeView('#')" onClick="changeDef('#')">#</span>

Now, a seperate .js file for this all, and yes I haven't forgotten to include it ;)

var the_num = defaultnum;
function changeView('num'){
if (num > the_num){
var color = "yellow";
}else if (num < the_num){
var color = "red";
}else{
var color = "black";
}
parent['viewchng'].innerHTML = "<font color="+color+">"+num+"</font>";
}
function changeDef('num'){
parent['setnum'].innerHTML = num;
}

The question: How to change the value of the_num to become num after the onclick. I have tried everything I know (which isn't a lot by way of JS) and nothing has worked. Please remember this is a very simplified version, and take note as well that these are arrays (if that makes any difference). If you need any additional info, and you think you can help me out, please PM me to let me know. Thanx in advance!

glenngv
12-17-2003, 01:49 AM
When you define parameters in a function, you don't put quotes in them.

function changeView(num){
...
}

function changeDef(num){
...
}

...

<span onMouseOver="changeView(1)" onClick="changeDef(1)">1</span>
<span onMouseOver="changeView(2)" onClick="changeDef(2)">2</span>

Fou-Lu
12-17-2003, 01:51 AM
Yeah, sorry there are no quotes in there.

The functions work fine in themselves, but I cannot get it to swap the values from the old value to the new one.

glenngv
12-17-2003, 02:13 AM
parent.document.getElementById('setnum').innerHTML = num;