Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How we fetch the value of textarea in prototype.js

    Hi all,
    I am using prototype js. I have fetch the value of textbox here, but right now unable to fetch the value of textarea....

    I am doing like below:

    <script language="javascript" type="text/javascript">

    var comm = document.post_comm.comment.value;

    alert(comm);

    </script>

    <textarea cols="80" rows="10" class="tb" id="comment" name="comment"></textarea>



    But i am getting null value here....

    after that i used (var comm = $('comment')
    it gives us some alert like: ([object HTMLTextAreaElement])


    plz help

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Or an even simpler way to do it, considering you have an id:

    Code:
    	var comm = document.getElementById("comment").value;
    	alert(comm);
    Definitely does the trick. Of course, if you are using jQuery...

    Code:
    var comm = $('comment')
    Would certainly return an object, considering what that does is... select element by name... at least from the looks of it, as opposed to getting the value of that element. All in all, if that's the only textarea in the document and you want to achieve the same result without getting by id...

    Code:
    	var comm = document.getElementsByTagName("textarea");
    	var comm = comm[0].value;
    	alert(comm);
    I'm sure there's at least a couple of other ways to do this thing, but eh... I'm not going to go through them all. Your original issue seems to come from a wrong reference to an object though. So if you don't want to use either of the shown results, look into that.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • #3
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    you can access any form element's value with $F('id')

    http://www.prototypejs.org/api/utility/dollar-f

  • #4
    New Coder
    Join Date
    Nov 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thankx to all////


  •  

    Posting Permissions

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