View Full Version : Textarea onClick on radio button

05-05-2004, 11:06 AM
How can i get a pre-populated text area when i click on the radio button. Initially there is no textarea on the form, I want it only after clicking on the radio button. I want to get the textarea contents from a collection(Java). Actually I do have a bean withe the values. How can i use the bean with the html:radio(Struts) tag?? So basically what do I do when onClick is performed?

05-05-2004, 01:15 PM
the initial java script code will look like that:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
text = new Array()
text[0] = 'first text';
text[1] = 'second text';
text[2] = 'third text';
function populate(r,f){
for(var i=0;i<f.elements[r].length;i++){
if (f.elements[r][i].checked){
var t=i;
<textarea name="txt" cols="20" rows="4"></textarea>
<input type="radio" name="radio" value="0" onclick="populate(this.name,this.form)">
first pre-defined text<br>
<input type="radio" name="radio" value="1" onclick="populate(this.name,this.form)">
<input type="radio" name="radio" value="2" onclick="populate(this.name,this.form)">


But you problem is that you must get the array's value from another data base build in another language (java-your case). This means that you need an application which must generate that array, or with the entire HTML page, or in an external JS file (which will include only the javascript code lines)

05-05-2004, 07:10 PM
Initially there is no textarea on the form, I want it only after clicking on the radio button.
You might want to use:

function populate(r,f) {
for(var i=0;i<f.elements[r].length;i++) {
if (f.elements[r][i].checked) {
var t=i;

if(t>-1) {
f.txt.style.visibility = "visible";
f.txt.style.display = "block";


<textarea name="txt" cols="20" rows="4" style="visibility:hidden; display:none"></textarea>

And yea, like Kor said, you're going to need to use your Java to fill that array with the information from the bean.

Good luck,