Forum Moderators: open

Message Too Old, No Replies

can't get arrays working in a function and for loop

Javascript for loop, functions, arrays

         

BungeeJumper

4:54 am on Aug 6, 2009 (gmt 0)

10+ Year Member



I am trying to replace avlues in a list. I have it where Ican replace one value with the code displayed using document.getElementById('60').innerHTML = '15';

But I need to iterate though the two arrays below (they are partial) to replace the rest of the values in the list. So far nothing I have tried seems to work.
What I have tried so far has been along the lines of

document.getElementById('catArray[i]').innerHTML = 'myArray[i]';

I know the array values are getting in the function (but I don't understand how they get in since I didn't send them as parameters) but I tried moving the function into the head section and send the arrays as parameters with the function call. First is the code that will update one item..., then my latest attempt at using arrays.

Firefoxes' error console is telling me getElementById is null, with or without the arrays as parameters.

How would I get it to iterate through the two arrays and change more?

Thanks for the help.

...........................................
.........................................
<script type="text/javascript">
document.write("Hello World!");
myArray = new Array(15,89,4,61,5)
catArray = new Array(60,65,69,2719)

var oFullParent = document.getElementById('69');

function changeText(){

var arLen=myArray.length;
for ( var i=0, len=arLen; i<len; ++i ){

}
document.getElementById('60').innerHTML = '15';
}
</script>
<p>Welcome to the site <b id='69'>dude</b> </p>
<input type='button' onclick='changeText()' value='Change Text'/>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


<script type="text/javascript">

myArray = new Array(15,89,4,61,5);
catArray = new Array(60,65,69,2719);

function changeText(catArray,myArray ){

var arLen=myArray.length;
for ( var i=0, len=arLen; i<len; ++i ){

document.getElementById('catArray[i]').innerHTML = 'myArray[i]';
}
}

</script>
<p>Welcome to the site <b id='69'>dude</b> </p>
<input type='button' onclick='changeText(catArray,myArray)' value='Change Text'/>

<?
echo '<div id="copy">
<button onclick="dochangepops(\'srcl\')">Get CD info</button>
</div>';

BungeeJumper

5:03 am on Aug 6, 2009 (gmt 0)

10+ Year Member



Thanks, but no thank eee haaaa. Found the problem. .. variables inside of quotes won't work. Problem solved