Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    populate a textarea with checkboxes and radio buttons

    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

    Code:
    <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;}
        }
        }
    </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 &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>
    Last edited by technotool; 06-09-2008 at 04:03 AM.

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Quote Originally Posted by technotool View Post
    Hi -i'm back. I know.
    I thought you were a new member

    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:
    Code:
    function populateTextArea(){
       var target = document.getElementById("targetarea")
       var inps=document.getElementById('pe_exam').getElementsByTagName('input');
       for(var i=0; i < inps.length; i++)
       {
    	if(inps[i].checked==true)
    		{
    		target.value+=inps[i].value+'\n';
    		}
       }
     }
    </script>
    BTW, language is a deprecated attribute for script tag. type will suffice

    Hope it helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    technotool (06-09-2008)

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    thanks

    thanks so much for your help. tech

  • #4
    New Coder
    Join Date
    Jun 2008
    Location
    127.0.0.1
    Posts
    43
    Thanks
    1
    Thanked 6 Times in 6 Posts
    EDIT: Sorry my bad lol.
    Last edited by Dondon; 06-12-2008 at 02:18 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •