You are quoting the brackets ']' thus creating a string as vehicleName's value and therefore arrayName's value. Take the quotes off the brackets and remove the + signs and then the string from the nodeValue will be in array.
The value of searchLocation.getElementsByTagName("vehicleName")[0].childNodes[0].nodeValue is:
'name','owa','owb','owc'
I tried removing the brackets and the + but it didnt work. Maybe the above text isn't a proper array?
Also, I tried changing the above searchLocation.getElementsByTagName("vehicleName")[0].childNodes[0].nodeValue 's value to:
['name','owa','owb','owc']
But it still didnt't work.... The above text are generated by Java, and sent to the web application through <vehicleName>['name','owa','owb','owc']</vehicleName>, and using the searchLocation.getElementsByTagName("vehicleName") would extract the data out, and will then be stored under the JS var vehicleName...
if (http.readyState == 4) {
if (http.status == 200) {
var searchLocation = http.responseXML.getElementsByTagName("searchLocation")[0];
var results;
if (searchLocation!=null){
results = searchLocation.getElementsByTagName("latlng")[0].childNodes[0].nodeValue.split(",");
var vehicleName = searchLocation.getElementsByTagName("vehicleName")[0].childNodes[0].nodeValue;//searchLocation.getElementsByTagName("vehicleName")[0].childNodes[0].nodeValue
//arrayName = ['name','Owa22','Owa23','Owa24'];
arrayName = vehicleName; //['name','Owa22','Owa23','Owa24'] <-- Problem here
alert('vehicleName '+vehicleName);
alert('arrayName[1] '+arrayName[1]);
}
whatever text you read from the DOM, javascript read it as a string type value. what you are expecting is to use that string and be treated as javascript statement. in that case you have to eval the string.
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
Bookmarks