technotool Posted June 9, 2008 Share Posted June 9, 2008 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> Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 9, 2008 Share Posted June 9, 2008 <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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.