user938407
user938407

Reputation: 11

Putting text into textbox in JavaScript from an array

I'm new to JavaScript and I am having problems putting information read from a created array into a text box.I am using Dashcode, but modifying elements in the main.js file as I go along. I have created an array, can get the value from the array, I just can't manage to get the information into the text box.

The line which doesn't work is:

document.getElementById("text").setAttribute("text",textLocation);

where text is the ID of the box, and textLocation is the information I am trying to pass into the text box.

If anyone could help it would be much appreciated.

The rest of the code is below.

var n = null;
var textLocation;
var myArray = new Array("info one","info 2","info 3","info 4","info 5","info 6","info 7","info 8","info 9");

function toPreviousImage(event)
{

    var list = document.getElementById("grid").object; 
    var selectedObjects = list.selectedObjects();
    var name = selectedObjects[0].valueForKey("name");
    var textinfo = selectedObjects[0].valueForKey("info"); 

    name= name - 1;

    if(!n || n == undefined){n=name} else {n--}

    textLocation = myArray[n];

    document.getElementById("text").setAttribute("text",textLocation);

Upvotes: 0

Views: 1145

Answers (1)

Nathan Manousos
Nathan Manousos

Reputation: 13848

I believe attribute you want to set is 'value', not 'text'.

document.getElementById("text").setAttribute("value",textLocation);

Upvotes: 1

Related Questions