Web Directory - Turquoise Rings - PT Cruiser - Property in Dubai - Anime Episodes

PDA

View Full Version : Writing into textarea


pixmania
May 5th 2009, 7:07 am
The code below writes whatever text value is presented in each text number, with an onlclick command.

The problem I cant figure out is, it replaces text, all text, where as I really wanted it just to write not replace.

For example a text file might be written as:
hello world
I wanted to be able to write:
hello world {$ad1}

But "hello world" gets removed and replaced with {$ad1}

Could some explain why maybe or supply a solution or alternative method?

<script type="text/javascript">
function textval(textnumber){
text = new Array()
text[1] = "{$ad1}"
text[2] = "{$ad2}"
text[3] = "{$ad3}"
text[4] = "{$ad4}"
text[5] = "{$ad5}"
document.form1.template.value=text[textnumber]
}
</script>

<a href = "#" onclick="textval(1);">Advert 1</a>
<a href = "#" onclick="textval(2);">Advert 2</a>
<a href = "#" onclick="textval(3);">Advert 3</a>
<a href = "#" onclick="textval(4);">Advert 4</a>
<a href = "#" onclick="textval(5);">Advert 5</a>


<br>

<form name="form1">
<textarea name="textarea2">
</textarea>
</form>

koko5
May 5th 2009, 8:31 am
document.form1.template.value += text[textnumber] ;)

pixmania
May 5th 2009, 8:34 am
document.form1.template.value += text[textnumber] ;)

Very good, thank you!