Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set TextArea value using Jquery

Tags:

html

jquery

I am only setting one simple value in text area using jquery on radio button click. but it sets nothing.

My Code is:

Javascript
---------
$("input[name=radio_workitem]").on("change",function(){

   $("input[name='workItemVO.note']",'#id_form_workitem_view').val("dummyNote");
}


<!-- language: lang-html -->

    <input type="radio" name="radio_workitem" value="<s:property value="workItemId"/>">

    <s:form id="id_form_workitem_view">
        <s:textfield name="workItemVO.subject" id="id_txt_wi_subject" class="form-control" readonly="true" />
        <s:textfield  name="workItemVO.createdBy" class="form-control" readonly="true"/>

        <s:textarea name="workItemVO.note"  class="form-control" rows="4"></s:textarea>

What I have Tried:

$("input[name='workItemVO.note']",'#id_form_workitem_view').html("dummyNote");
$("input[name='workItemVO.note']",'#id_form_workitem_view').text("dummyNote")

Doesn't work.

Here: if I set value using text area id, it works properly example: $("#Note").val("dummyNote"); // works fine

But I want to use "Name" not "Id"

Plz help, i am very new in Stack overflow, may be some mistake in my description. Plz let me know.

Thanks in Advance

like image 391
Abhishek Singh Avatar asked Aug 18 '15 09:08

Abhishek Singh


People also ask

How to set value for textarea in jQuery?

Answer: Use the jQuery val() Method You can simply use the val() method to set the value of a textarea dynamically using jQuery.

Can we use value in textarea?

<textarea> does not support the value attribute.

Can textarea have default value?

The DOM Textarea defaultValue Property is used to set or return the default value of the textarea field. Syntax: It is used to return the defaultValue property.


1 Answers

input[name='workItemVO.note'] //this won't work because textArea is not an input

use textarea instead of input

$("textarea[name='workItemVO.note']").val('dummyNote')

JSFIDDLE DEMO

like image 143
Dyrandz Famador Avatar answered Sep 19 '22 22:09

Dyrandz Famador