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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy I'm a newbie...be gentle help needed urgent html jscript

    hi i am trying to populate a textarea with the selections
    like
    checkboxes
    radiobuttons
    textbox
    combobox

    but i cant seem to do so. i am naive to the field of programing, and found a few code snippets to do so i tried but it did no good... help needed

    this is my code
    "

    <html>
    <head>
    <style type="text/css">

    .minitext { font: normal 0.7em Arial, sans-serif; color: Black; }

    .disable {
    background-color: #CF110C;
    color: #fff;
    font-weight: bold;
    padding: 5px;
    }

    </style>



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

    function populateTextArea(){

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


    while (fieldObj = document.MyForm['iid'+fieldID]) {

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

    fieldID++;
    }// end of while

    document.getElementById('targetarea').value = output.join(', ');
    //document.MyForm.targetarea.value = document.MyForm.ip1.value + '\n' + document.MyForm.ip2.value + '\n' + document.MyForm.ip3.value ;
    }

    </script>
    </head>

    <body>
    <br>
    <br>

    <form name="MyForm" method="POST" action="#">

    String 1: <input type="text" name="ip1" value=""><br>
    String 2: <input type="text" name="ip2" value=""><br>
    String 3: <input type="text" name="ip3" value=""><br><br>


    <input type="checkbox" name="iid1" id="pe_item2" value="Text string 1"> Text string
    <input type="checkbox" name="iid1" id="pe_item2" value="Text string 12"> Text string 1<br><br><br>

    <input type="radio" name="iid2" id="pe_item4" value="Text string 2">Text string 2
    <input type="radio" name="iid2" id="pe_item6" value="Text string 3">Text string 3<br>
    <input type="radio" name="iid3" id="pe_item8" value="Text string 4">Text string 4
    <input type="radio" name="iid3" id="pe_item10" value="Text string 5">Text string 5<br>
    <input type="radio" name="iid4" id="pe_item12" value="Text string 6">Text string 6
    <input type="radio" name="iid4" id="pe_item14" value="Text string 7">Text string 7<br>


    <br>



    <br>
    <a href="#" onClick="document.MyForm.targetarea.value = document.MyForm.ip1.value + '\n' + document.MyForm.ip2.value + '\n' + document.MyForm.ip3.value + populateTextArea();" >Populate</a><br>
    <br>
    <INPUT TYPE=BUTTON VALUE="Co" ONCLICK= populateTextArea(); >
    <br>

    <textarea id="targetarea" name ="targetarea" cols="50" rows="5"></textarea>
    </form>



    </body>
    </html>


    "

    help need this done urgently

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I find your element names rather confusing.

    Code:
    <form name="MyForm" method="POST" action="#">
    
    String 1: <input type="text" name="ip1" value=""><br>
    String 2: <input type="text" name="ip2" value=""><br>
    String 3: <input type="text" name="ip3" value=""><br><br>
    
    
    <input type="checkbox" name="cbox1" id="pe_item1" value="Text string 1"> Text string 
    <input type="checkbox" name="cbox2" id="pe_item2" value="Text string 12"> Text string 1<br><br><br>
    
    <input type="radio" name="iid2" id="pe_item4" value="Text string 2">Text string 2
    <input type="radio" name="iid2" id="pe_item6" value="Text string 3">Text string 3<br> 
    
    <input type="radio" name="iid3" id="pe_item8" value="Text string 4">Text string 4
    <input type="radio" name="iid3" id="pe_item10" value="Text string 5">Text string 5<br>
    
    <input type="radio" name="iid4" id="pe_item12" value="Text string 6">Text string 6
    <input type="radio" name="iid4" id="pe_item14" value="Text string 7">Text string 7<br>
    
    
    <br>
    
    
    
    <br>
    
    <INPUT TYPE=BUTTON VALUE="Populate Text Area" ONCLICK= populateTextArea(); >
    <br>
    
    <textarea id="targetarea" name ="targetarea" cols="50" rows="5"></textarea>
    </form>
    
    <script type = "text/javascript">
    function populateTextArea(){
    var f = document.MyForm;
    var a1 = f.ip1.value;
    var a2 = f.ip2.value;
    var a3 = f.ip3.value;
    if (f.cbox1.checked) {var c1 = f.cbox1.value}
    if (f.cbox2.checked) {var c2 = f.cbox2.value}
    if (f.iid2[0].checked) {var r1 = f.iid2[0].value}
    if (f.iid2[1].checked) {var r1 = f.iid2[1].value}
    if (f.iid3[0].checked) {var r2 = f.iid3[0].value}
    if (f.iid3[1].checked) {var r2 = f.iid3[1].value}
    if (f.iid4[0].checked) {var r3 = f.iid4[0].value}
    if (f.iid4[1].checked) {var r3 = f.iid4[1].value}
    
    var message = "";
    if (a1) {message += a1 + "\n"} 
    if (a2) {message += a2 + "\n"}
    if (a3) {message += a3 + "\n"}
    if (c1) {message += c1 + "\n"}
    if (c2) {message += c2 + "\n"}
    if (r1) {message += r1 + "\n"}
    if (r2) {message += r2 + "\n"}
    if (r3) {message += r3 + "\n"}
    
    f.targetarea.value = message;
    }
    
    </script>

    Quizmaster: Which musical, written in 1953 by Robert Wright and George Forrest, was set in medieval Baghdad?
    Contestant: South Pacific.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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