I want to pass array[x] to a variable so that I can use the variable in .innerHTML. I've researched and not found a reference.
Any help appreciated. Big thanks.
I want to pass array[x] to a variable so that I can use the variable in .innerHTML. I've researched and not found a reference.
Any help appreciated. Big thanks.
What are the values of the array? And which item in the array do you want to pass to a variable?
function captionToDiv() {
document.getElementById("captionHere").innerHTML = captionsList[caption];
return false;
}
This code does not work. If I could pass captionsList[caption] to a variable, maybe it would then work.?
Javascript Does Not Support Associative Arrays
http://www.hunlock.com/blogs/Mastering_Javascript_Arrays
I think easier would be to make it something like captionsList[0] to work.
Javascript Does Not Support Associative Arrays
http://www.hunlock.com/blogs/Mastering_Javascript_Arrays
I think easier would be to make it something like captionsList[0] to work.
Thanks! I was able to create an array from text. Would you like the code?
you maybe did emulation of associative array?
In the article it says that its possible.
Javascript does not have, and does not support Associative Arrays. However… All arrays in Javascript are objects and Javascript's object syntax gives a basic emulation of an associative Array.
Yeah, would be interesting to see a code.
I had lots of help with this.
<script type="text/javascript">
function captionsToCaptionsList() {
try{
txtFile = new XMLHttpRequest();
}
catch(e){
try{
txtFile = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try{
txtFile = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
alert("Ajax not supported by your browser!");
return false;
}
}
}
txtFile.open("GET", "paintinglist.txt", true);
txtFile.onreadystatechange = function() {
if (txtFile.readyState === 4) {// Makes sure the document is ready to parse.
if (txtFile.status === 200) {// Makes sure it's found the file.
captionsList = txtFile.responseText.split("\n");
}
}
}
txtFile.send(null);
}
captionsToCaptionsList();
</script>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.