简体   繁体   中英

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);

我相信您要设置的属性是“值”,而不是“文本”。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM