Writing into textarea

Discussion in 'JavaScript' started by pixmania, May 5, 2009.

  1. #1
    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
    Code (markup):
    I wanted to be able to write:
    hello world {$ad1}
    Code (markup):
    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>
    PHP:

     
    pixmania, May 5, 2009 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    document.form1.template.value += text[textnumber]
    HTML:
    ;)
     
    koko5, May 5, 2009 IP
  3. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Very good, thank you!
     
    pixmania, May 5, 2009 IP