PDA

View Full Version : Dynamically replace Array content.



shakemelikeapig
03-16-2012, 11:48 PM
Hello All,

I have a code which works fine for what is does but I want to add in dynamically a new list to the Array...... from an input field.

The relevent part of the code reads as this for example........

var step_x_list=new Array("ca1sb2en1pg1itm1","ca1sb2en1pg1itm2","ca1sb2en1pg1itm3")

but I need a way to dynamically replace the existing.... "ca1sb2en1pg1itm1","ca1sb2en1pg1itm2","ca1sb2en1pg1itm3" seen above with a new list from an input field which holds the following say....... ca2sb2en2pg1itm1","ca2sb2en2pg1itm2","ca2sb2en2pg1itm3

I have tried various ideas but none seem to be able to inject the new values in the space between the brackets.

Any thoughts.



For those just wondering what the code is and want to try it, it is a one piece code which can fire many different functions without requiring lots of individual bits of code to do same. The action usually happens in micro-seconds but I slowed it to a one second count between changes so you can see what is actually happening.

Below is a revised code if you want to see it working and also to give an idea about the Array part in which I want to add a different number set.
Copy the code and save in notepad as test.html
It can be opened as a web page. Remember to change the code tags to the correct script tags


var i_x_list=0
function fireFunctionList_x_list()
{
if (document.getElementById("locate_load_x_list").value == "end" || document.getElementById("locate_load_x_list").value == "undefined"){i_x_list=0;document.getElementById("locate_load_x_list").value=""}else{fireFunctionList_x_list_do()}
}
function fireFunctionList_x_list_do()
{
document.getElementById("addto").value="place_";
var step_x_list=new Array("ca1sb2en1pg1itm1","ca1sb2en1pg1itm2","ca1sb2en1pg1itm3","ca1sb2en1pg1itm4","ca1sb2en1pg1itm5","ca1sb2en1pg1itm6","ca1sb2en1pg1itm7",
"ca1sb2en1pg1itm8","ca1sb2en1pg1itm9","ca1sb2en1pg1itm10","ca1sb2en1pg1itm11","ca1sb2en1pg1itm12","ca1sb2en1pg1itm13","ca1sb2en1pg1itm14","end")
document.getElementById('locate_load_x_list').valu e=step_x_list[i_x_list]
i_x_list=i_x_list+1
document.getElementById("addto").value+=document.getElementById("locate_load_x_list").value;
document.getElementById("final_locate_load_x_list").value=document.getElementById("addto").value;
document.getElementById("final_locate_load_x_list").value+=document.getElementById("addto2").value;
var x_list = document.getElementById("final_locate_load_x_list").value;
setTimeout("fireFunctionList_x_list()",1000)
var f_x_list = new Function(x_list); f_x_list();
}


CF