View Full Version : How we fetch the value of textarea in prototype.js

03-24-2009, 10:53 AM
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;



<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

03-24-2009, 04:15 PM
Or an even simpler way to do it, considering you have an id:

var comm = document.getElementById("comment").value;

Definitely does the trick. Of course, if you are using jQuery...

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...

var comm = document.getElementsByTagName("textarea");
var comm = comm[0].value;

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.

03-25-2009, 03:58 PM
you can access any form element's value with $F('id')


04-06-2009, 02:47 PM
Thankx to all////