PDA

Click to See Complete Forum and Search --> : Javascript Dynamic text



Ryoku
01-22-2007, 09:30 PM
I would first like to say that I have a very lose grasp of Javascript to start with. Iíve gone over various javascript learning sights and have a basic grasp of the language, if that.

Iím trying to get a page to dynamicly change text in a window from data stored in an external array. I have a function script set up in the links so that on click its supposed to update the value of the variable which is to be written in the area where I want the text however when I click the link the script clears the page and adds the information from the array.

Below is an example of the test I was running someone please help. I canít go out and get a book until the first of the month.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var texts= new Array(3)
texts[0] = "text1"
texts[1] = "text2"
texts[2] = "text3"
texts[3] = "This is the default text"

var textarea = texts[3]

function click1(){
textarea = texts[0]
}

function click2(){
textarea = texts[1]
}

function click3(){
textarea = texts[2]
}

</script>
</head>

<body>
<a href="javascript:click1()">link1</a>
<a href="javascript:click2()">link2</a>
<a href="javascript:click3()">link3</a>
<br />
<script type="text/javascript">
document.writeln(textarea)
</script>
</body>
</html>


I was working with the "document.open()" and "document.close()" variables but those didnt seem to have any effect.

please help

rdoyle720
01-23-2007, 02:01 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var texts= new Array(3)
texts[0] = "text1"
texts[1] = "text2"
texts[2] = "text3"
texts[3] = "This is the default text"

var textarea = texts[3]

function click1(){
textarea = texts[0]
document.getElementById("writeArea").innerHTML=textarea;
}

function click2(){
textarea = texts[1]
document.getElementById("writeArea").innerHTML=textarea;
}

function click3(){
textarea = texts[2]
document.getElementById("writeArea").innerHTML=textarea;
}

</script>
</head>

<body>
<a href="javascript:click1()">link1</a>
<a href="javascript:click2()">link2</a>
<a href="javascript:click3()">link3</a>
<br />
<p id="writeArea">
<script type="text/javascript">
document.writeln(textarea)
</script>
</p>
</body>
</html>