Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Adding Text Into Textbox with JavaScript

  1. #1
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default Adding Text Into Textbox with JavaScript

    How is it possible to put text into a textbox using JavaScript?

    -magicyte
    Last edited by magicyte; 07-31-2008 at 04:49 PM.

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Adding text to a textbox?! Impossible!

    Just joking. It's completely possible, and very easy to do.

    Method 1: Using an ID
    Code:
    function add(text){
        var TheTextBox = document.getElementById("Mytextbox");
        TheTextBox.value = TheTextBox.value + text;
    }
    Method 2: using the form:
    Code:
    function add(text){
        var TheTextBox = document.forms[0].elements['field_name']; //I think that's right, haven't done it in a while
        TheTextBox.value = TheTextBox.value + text;
    }
    Last edited by Jas; 07-28-2008 at 09:45 PM. Reason: typo
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #3
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Here you go magicyte:
    Code:
    <script type="text/javascript">
    function insertText(val,e){
    document.getElementById(e).innerHTML+=val;
    }
    </script>
    <textarea id="textIns"></textarea><br />
    <a href="javascript:insertText('Hello ','textIns');" onClick="void(0)">Insert 'Hello'</a><br /><a href="javascript:insertText('GoodBye ','textIns');" onClick="void(0)">Insert 'GoodBye'</a>
    Edit: Jas beat me . I personally thing that my idea is more convenient, though.
    Jeremy | jfein.net

  4. #4
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Nile: heh. Cross post

    Magicyte: . . . so what was the point of your post?
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  5. #5
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    I wuz bored and I wanted to see if anyone thought that I was that dumb.

    -magicyte

  6. #6
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by magicyte View Post
    Using the .value attribute is easy. Just do this: document.getElementById('cool').value = 'po'; <input type="text" id="cool">

    Any other .value attribute comments?

    -magicyte
    Yeah, why'd you update your post?
    Jeremy | jfein.net

  7. #7
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Please don't put up posts like that again. If you have nothing else to do, start a topic in "The Lounge."

    EDIT: And in response to your edit of the last post, not knowing that does not make one dumb. There are many beginners that use this website looking for simple answers.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  8. #8
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Yeah. I'm sorry. I do think I should be put in Forums Jail.

    -magicyte

    P.S. {:-(

  9. #9
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Quote Originally Posted by magicyte View Post
    I do think I should be put in Forums Jail.
    So you'll come quietly, then? j/k
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  10. #10
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry if i sound stupid but is it possible to pass a JS variable into the
    text value

    e.g. var new ="somethign";
    <a href="javascript:insertText(' var new ' ,'user_location');" onClick="void(0)">Insert 'Hello'</a>

    so when you click it

    somethign will be displayed in the box instead of the var new text being displayed

    i want to out put the contents of the variable not the name of it
    thanks in advance

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •