SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using value from textarea

    hi,

    here suppose i get value from textarea using following

    Code JavaScript:
    var text = document.getElementById.("textarea").value; 
    var input = document.getElementById.("textfield").value;
     
    alert(text);
     
    input = text;

    Asssume text in textarea as - test
    alerts string test
    and asigns value of textfield as test.

    Asssume text in textarea as - "test"
    alerts string "test"
    and asigns value of textfield as " test=".

    How to solve this?

  2. #2
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd have to use innerHTML on textareas as it's not a form field with a value

  3. #3
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ruben K. View Post
    You'd have to use innerHTML on textareas as it's not a form field with a value
    Code JavaScript:
    var text = document.getElementById.("textarea").innerHTML;

    now takes blank string, even if i have written test in the textarea.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    .innerText ?? or .text ??
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why use innerHTML? A textareas value is retrieved with the value property.

    To set the text fields value:
    Code:
    var input = document.getElementById.("textfield");
    input.value = text;

  6. #6
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know how to take value from textarea, i always use .value on textarea's it was Ruben K. who suggested to use innerHTML. Pepejeria you haven't answered my question, please do if you have the time

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand the question, but shouldn't it be as simple as this?
    Code JavaScript:
    var text = document.getElementById.("textarea").value; 
    document.getElementById.("textfield").value = text;
    Birnam wood is come to Dunsinane

  8. #8
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cssExp View Post
    I know how to take value from textarea, i always use .value on textarea's it was Ruben K. who suggested to use innerHTML. Pepejeria you haven't answered my question, please do if you have the time
    Can you please rephrase the question? I also didn't really get it.

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    I don't understand the question, but shouldn't it be as simple as this?
    Code JavaScript:
    var text = document.getElementById.("textarea").value; 
    document.getElementById.("textfield").value = text;
    It should be that simple but there's a slight problem. There shouldn't be a fullstop after getElementById

    The following should work with no trouble

    Code JavaScript:
    var text = document.getElementById("textarea");
    var input = document.getElementById("textfield");
    input.value = text.value;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You all misunderstood! I know how to take a value from textarea and apply it to a input field, if you look at the code i posted on first post you can understand that!

    The problem is simple, i can assign the value of textarea in to hidden textfield, no problem. the problem is lets say the value of textarea is "test" including the quotes then the value stored becomes value="" test="" instead of value=""test"" (which i could correct it by adding \ to the ") but the problem does not occur if i alert() the textarea value, but only when i assign it to textfield.

    I know how to assign a value to other!, please go through my first post you'll understand the problem.

  11. #11
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cssExp View Post
    You all misunderstood! I know how to take a value from textarea and apply it to a input field, if you look at the code i posted on first post you can understand that!
    You are actually changing the string "input" to be the same as the string "text". You are not setting the textfield's value. There should also not be any dot after getElementById as Paul pointed out.
    Quote Originally Posted by cssExp View Post
    The problem is simple, i can assign the value of textarea in to hidden textfield, no problem. the problem is lets say the value of textarea is "test" including the quotes then the value stored becomes " test=" instead of "test" but the problem does not occur if i alert() the textarea value, but only when i assign it to textfield.

    I know how to assign a value to other!, please go through my first post you'll understand the problem.
    I still don't get it sorry. Where did the "=" come from?

    You need to properly escape the double quotes, or use single quotes combined with double quotes (can u say that 3 times really fast?).

  12. #12
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    There shouldn't be a fullstop after getElementById
    Oops! Didn't notice that one when I copied and pasted from the OP.

    I think the problem is with how you assign the text value back to the input field. It may also be a problem when you try to post a form control with a value that contains quotation marks. The '=' sign indicates some sort of MIME encoding attempt, I think.
    Birnam wood is come to Dunsinane

  13. #13
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still don't get it sorry. Where did the "=" come from?
    that's what i'd like to know the value becomes value="" test="" instead of value=""test""

    I don't think i can explain the problem well, guess it's best left unsolved. Sorry for the trouble.

    Maybe I'll completely rephrase the question tomorrow.

  14. #14
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to show us how you assign the value to the input field. All you've shown so far is how you assign it to a variable.
    Birnam wood is come to Dunsinane


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
  •