View Full Version : populate a textarea with checkboxes and radio buttons

06-09-2008, 04:24 AM
Hi -

I am trying to Populate(onClick) a textarea with checked items from a selection of radiobuttons and checkboxes. The enduser will make necessary selections and then click populate to fill the textarea with selected items. here is what I have thusfar.

In a div container id="pe_exam", checkboxes and radiobuttons are ordered by the id= ' "pe_item"+n ' as below however when I click populate noting is being populated. any assistance would be greatly appreciated. technotool

<script language="Javascript" type="text/javascript">

function populateTextArea(){
var target = document.getElementById("targetarea")
for(var i=0; i < 1000; i++){
if (document.getElementByTagName("pe_exam").getElementById("pe_item"+i).checked == true){
target.value = target.value + " " + document.getElementByTagName("pe_exam").getElementById("pe_item"+i).value
} else {continue;}
<textarea id="targetarea" cols="100" rows="5"></textarea>

<br><b>Physical Exam:</b><br>
<form name="form_pe" method="" action="">

<a href="#" onClick="populateTextArea();">Populate</a>

<div id="pe_exam">
<input type="radio" name="pe_gen1" id="pe_item2" value="alert and oriented x 3">A &amp; O x3 <br>
<input type="radio" name="pe_gen2" id="pe_item4" value="No apparent distress">NAD
<input type="radio" name="pe_gen2" id="pe_item6" value="Obvious distress">Obvious distress<br>
<input type="radio" name="pe_gen3" id="pe_item8" value="normal respiation">Normal Respiration
<input type="radio" name="pe_gen3" id="pe_item10" value="Labored Respiration">Labored Respiration <br>
<input type="radio" name="pe_gen4" id="pe_item12" value="normal mood">Normal mood
<input type="radio" name="pe_gen4" id="pe_item14" value="Depressed Mood">Depressed Mood<br>

06-09-2008, 05:05 AM
Hi -i'm back. I know.

I thought you were a new member :rolleyes:

Anyway, your script is erroneous. There are a number of them that don't even exist in JS. Take for instance document.getElementsByTagName. Note the highlighted in red.

I'm not always good at explaining things, but hopefully, this modification might help:

function populateTextArea(){
var target = document.getElementById("targetarea")
var inps=document.getElementById('pe_exam').getElementsByTagName('input');
for(var i=0; i < inps.length; i++)

BTW, language is a deprecated attribute for script tag. type will suffice ;)

Hope it helps.

06-09-2008, 05:44 PM
thanks so much for your help. tech

06-12-2008, 03:15 AM
EDIT: Sorry my bad lol.