Jump to content

populate textarea with checkboxes and radiobuttons


technotool

Recommended Posts

Hi -i'm back. I know.

 

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 pe = document.getElementByTagName("pe_exam")
   var items = pe.getElementById('pe_item' + i)
   var target = document.getElementById("targetarea")
   for(var i = 0; i < items.length; i++)
   {
    if (items[i].checked == true){
    target.value = target.value + items[i].value   
    }
    else {
    
    }
}
</script>
</head>
<body>
<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>

General<br>
<div id="pe_exam">
<input type="radio" name="pe_gen1" id="pe_item2" value="alert and oriented x 3">A & 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>

Link to comment
Share on other sites

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

function populateTextArea(){

  var output = new Array();
  var fieldID = 1;

  while (fieldObj = document.form_pe['pe_gen'+fieldID]) {

    if (fieldObj.length) {
      for (var j=0; j<fieldObj.length; j++) {
        if (fieldObj[j].checked) {
          output[output.length] = fieldObj[j].value;
        }
      }
    } else {
      if (fieldObj.checked) {
        output[output.length] = fieldObj.value;
      }
    }

    fieldID++;
  }

  document.getElementById('targetarea').value = output.join(', ');

}
</script>

</head>

<body>

<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>

General<br>
<form name="pe_exam">
  <input type="checkbox" name="pe_gen1" id="pe_item2" value="alert and oriented x 3">A & 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>
</form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.