Konrad Viltersten
Konrad Viltersten

Reputation: 39148

Not able to set the text in an textarea using jQuery and value method

I've got the following markup:

<textarea id="hazaa"></textarea>

When I execute the following JavaScript in the console:

$("#hazaa").value

I get the print-out of what's in the box. However, when I try to execute this:

$("#hazaa").value = "shazoo"

the console notifies me back with shazoo but the text in the box doesn't change. Also, subsequent check of what's in the box returns the old, unaltered value.

It's been a while since I've done any jQuery-ing so it's probably something fairly obvious but I can't think of any resolution. I've googled for suggestions but the best one I've found actually discusses properties that aren't there! What am I missing?!

Executing the following two lines:

$("#hazaa").val
$("#hazaa").val()

produces:

undefined
TypeError: Object # has no method 'val'

I trust fully that I'm to blame for it but I don't how how to proceed. :)

Upvotes: 3

Views: 8233

Answers (2)

Adil Shaikh
Adil Shaikh

Reputation: 44740

You need to do this -

setter

$("#hazaa").val("shazoo");

getter

var val = $("#hazaa").val();

Demo --> http://jsfiddle.net/E3kZy/1/

Upvotes: 3

PSR
PSR

Reputation: 40328

You can set value by using .val()

Set the value of each element in the set of matched elements.

   $("#hazaa").val('Your text here');

.val()

You can get the value using $("#hazaa").val();

Upvotes: 0

Related Questions