6

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

Abhishek Singh
  • 1,367
  • 1
  • 22
  • 46
  • See http://stackoverflow.com/questions/1107220/how-can-i-select-an-element-by-name-with-jquery meaby you should use $("textarea[name=workItemVO.note]", ...) – aSoler Aug 18 '15 at 09:50

2 Answers2

4
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

Dyrandz Famador
  • 4,499
  • 5
  • 25
  • 40
1

<textarea/> is not an <input/>.

You can use the :input selector, or simply specify textarea[name="..."]

Your on change listener is missing a ) at the end, but I assume that's a copy and paste error.

Provided that <s:textarea/> does indeed render as a textarea with the name intact your code will work if you use the textarea selector.

David Hedlund
  • 128,221
  • 31
  • 203
  • 222