h-rai
h-rai

Reputation: 3974

how to set the contents of a textarea in HTML by passing a String from a servlet to it

I am trying to pass the value of a string to a textarea so it would be visible in the textarea. Looks like there is no attribute like 'value' in textarea.

Upvotes: 2

Views: 3167

Answers (4)

h-rai
h-rai

Reputation: 3974

I tried the following code and it worked. I just entered the string within the textarea tags as follows: String value

<% String textAreaValue = session.getAttribute("textArea"); %>

<textarea rows = "4" cols = "20" name = "area" id = "area"><% if(condition) { %>
<%=textAreaValue %><%}%> </textarea>

Upvotes: 1

MaVRoSCy
MaVRoSCy

Reputation: 17839

you can also set its contents using JQuery by:

$("#id_of_textarea").val("here is your message");

or using javascript by:

document.getElementById("id_of_textarea").value = "here is your message";

Upvotes: 0

Vikdor
Vikdor

Reputation: 24124

The attribute on text area to set the content is textarea.innerText for IE and textarea.textContent for firefox.

Upvotes: 3

jondinham
jondinham

Reputation: 8511

The 'textarea' tag does have attribute 'value', see: http://www.w3schools.com/jsref/dom_obj_textarea.asp

In case you want to put the content in textarea to be a string gotten from server, you must call to the server to get the value by AJAX from your JavaScript code. A little guide: http://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp

There are other advanced methods to do this with Java Applet, ActiveX,... but this is for advanced purposes only.

Upvotes: 4

Related Questions