#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    69
    Rep Power
    12

    javascript function within a textarea


    i was wondering did anyone know how i could run a javascript function within a textarea

    i did the following
    <textarea rows="10" cols="100"name="des">
    <script>
    displayCart();
    </script>
    </textarea>


    the above example does not work as it just prints <script>
    displayCart();
    </script>
    into my textarea
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Canberra, Australia
    Posts
    348
    Rep Power
    14
    You need to set the value of the text field from a JS function. Either from within displayCart or you could write another one.

    As far as I know you can not call a function from within a text area, because it is only text.

    <script>

    displayCart();

    document.FormName.des.value = displayCart();

    </script>



    <body onload="displayCart();">

    <textarea rows="10" cols="100"name="des">

    </textarea>

    </body>

    hope I helped/
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    69
    Rep Power
    12
    no it does not work i get an error document.FormName.des is null or not an object
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Canberra, Australia
    Posts
    348
    Rep Power
    14
    document.FormName.des this is the access to your field.

    So FormName relates to the name of your form and des relates to the name of your field

    <html>
    <head>
    <title>Try This</title>

    <script>
    function inputText() {
    document.testform.descript.value = "the red ball";
    }
    </script>
    </head>

    <body>

    <form name="testform">
    <textarea name="descript"></textarea>

    <input type="button" value="input text" name="input text" onclick="inputText();">

    </form>

    </body>
    </html>

    Hopefully this script demonstrates to you how to input a value into a text area.

IMN logo majestic logo threadwatch logo seochat tools logo