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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Textarea onClick on radio button

    How can i get a pre-populated text area when i click on the radio button. Initially there is no textarea on the form, I want it only after clicking on the radio button. I want to get the textarea contents from a collection(Java). Actually I do have a bean withe the values. How can i use the bean with the html:radio(Struts) tag?? So basically what do I do when onClick is performed?
    Last edited by syedali77; 05-05-2004 at 11:26 AM.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    the initial java script code will look like that:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    script>
    text = new Array()
    text[0] = 'first text';
    text[1] = 'second text';
    text[2] = 'third text';
    function 
    populate(r,f){
    t=-1;
    for(var 
    i=0;i<f.elements[r].length;i++){
    if (
    f.elements[r][i].checked){
    var 
    t=i;
    }
    }
    if(
    t>-1)
    {
    f.txt.value=text[t]
    }
    }
    </script>
    </head>
    <body>
    <form>
    <textarea name="txt" cols="20" rows="4"></textarea>
      <br>
      <br>
     <input type="radio" name="radio" value="0" onclick="populate(this.name,this.form)">
      first pre-defined text<br>
     <input type="radio" name="radio" value="1" onclick="populate(this.name,this.form)">
      second<br>
     <input type="radio" name="radio" value="2" onclick="populate(this.name,this.form)">
      third<br>

    </form>
    </body>
    </html> 
    But you problem is that you must get the array's value from another data base build in another language (java-your case). This means that you need an application which must generate that array, or with the entire HTML page, or in an external JS file (which will include only the javascript code lines)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by syedali77
    Initially there is no textarea on the form, I want it only after clicking on the radio button.
    You might want to use:
    Code:
    function populate(r,f) { 
     t=-1; 
     for(var i=0;i<f.elements[r].length;i++) { 
      if (f.elements[r][i].checked) { 
       var t=i; 
      } 
     } 
    
     if(t>-1) {
      f.txt.value=text[t];
      f.txt.style.visibility = "visible";
      f.txt.style.display = "block";
     } 
    } 
    
    ...
    
    <textarea name="txt" cols="20" rows="4" style="visibility:hidden; display:none"></textarea>
    And yea, like Kor said, you're going to need to use your Java to fill that array with the information from the bean.

    Good luck,
    Sadiq.


  •  

    Posting Permissions

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