0

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);
1
  • You may find the developer mneu, esp. Web Inspector, in Safari handy for debugging, if you haven't discovered it yet. Commented Sep 11, 2011 at 23:54

1 Answer 1

1

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

document.getElementById("text").setAttribute("value",textLocation);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.