Change contents of textareawhen pressing a button.

Discussion in 'JavaScript' started by blueparukia, Sep 23, 2007.

  1. #1
    Say I have three buttons and a textarea, when I press a button, I want all the text in the text area replaced by a preset JavaScript variable (so if the variable = "hello", all the text in the textarea will be replaced by "hello" on buton press.) If possible, I would like a confirmation box to appear first (e.g: "Are you sure"? - if you press yes it replaces the ext, if you press no, it doesn't).

    I need this done for three different buttons.

    My current HTML:
    <textarea name="code" class="mainscript" cols="100" rows="50">
    <input name="butt1" type="button" value="Button1"><input name="butt2" type="button" value="Button1"><input name="butt3" type="button" value="Button1">
    Code (markup):
    Cheers,

    BP
     
    blueparukia, Sep 23, 2007 IP
  2. meetgs

    meetgs Active Member

    Messages:
    957
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    70
    #2
    add id="code" to the textarea:
    <textarea name="code" id="code" class="mainscript" cols="100" rows="50">

    <input name="butt1" type="button" value="Button1" onclick="document.getElementById('code').value = 'hello';">


    you should be able to change the literal "hello" to a variable.
     
    meetgs, Sep 24, 2007 IP
  3. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #3
    Thanks you alot :D
     
    blueparukia, Sep 24, 2007 IP