SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2010
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Populate textarea based on radio button selection

    I've figured out how to get contents into a textarea based on a radio button selection.

    Code:
    <script>
    text = new Array()
    text[0] = Array('Saab','Volvo','BMW'); 
    text[1] = 'second list';
    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)">
      Default List&nbsp;&nbsp;
     <input type="radio" name="radio" value="1" onClick="populate(this.name,this.form)">
      Another List&nbsp;&nbsp;
    
    </form>
    But what I can't figure out is how to separate the lists line-by-line. For example: presenting the first selection above as

    Saab
    Volvo
    BMW

    as opposed to

    Saab, Volvo, BMW

    I assumed I would have to make an array within as array to accomplish this. Am I on the right track?

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Location
    Kingdom of Saudi Arabia
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    replace with below portion...

    Code javascript:
    if(t>-1){
        f.txt.value= text[t].toString().replace(/,/gi,"\n");
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2010
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice, thanks man. I appreciate it

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by soma56 View Post
    I assumed I would have to make an array within as array to accomplish this. Am I on the right track?
    I assume you mean a multi-dimensional array? Mind expanding on the thought? I'm trying to vision it in my head, but I don't see where you're tryin to go..
    TierEngine - Reliable Dedicated Servers and Colocation
    99.9% Uptime Guaranteed
    View our Dedicated Server Deals!
    Have questions? We can help. 888.233.6133 - support(at)tierengine.com


Bookmarks

Posting Permissions

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