Results 1 to 4 of 4

Thread: Generate an array from onchange selection

  1. #1
    Join Date
    Jan 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Generate an array from onchange selection

    I have an array that I would like to dynamically generate based on what a user selects in a drop down box, is there anything on the boards that has been created alreay similar I am not search correctly on? Thanks

    <select name="photoarray" onchange="">
    <option value="1">1 Photo</option>
    <option value="2" >2 Photos</option>
    <option value="3">3 Photos</option>
    <option value="4">4 Photos</option>
    <option value="5">5 Photos</option>
    <option value="6">6 Photos</option>
    <option value="7">7 Photos</option>
    <option value="8">8 Photos</option>
    <option value="9">9 Photos</option>
    <option value="10">10 Photos</option>
    </select>

    If option 4 Photos is selected in the photoarray select box would produce,
    var files = new Array("photo1.jpg", "photo2.jpg", "photo3.jpg", "photo4.jpg")

    And if 6 Photos is selected it would produce,
    var files = new Array("photo1.jpg", "photo2.jpg", "photo3.jpg", "photo4.jpg",”photo5.jpg”,”photo6.jpg”)

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    Hi there dotcomtim,

    does this example help...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    window.onload=function() {
    document.forms[0][0].onchange=function() {
       files=new Array();
       num=this.value;
    for(c=0;c<num;c++) {
       files[c]='photo'+(c+1)+'.jpg'; 
     }
       alert(files);
       alert('the first image in the array is...\n\n'+files[0]);
       alert('the last image in the array is...\n\n'+files[c-1]);
    
      }
     }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <div>
    <select name="photoarray" onchange="">
      <option value="1">1 Photo</option>
      <option value="2" >2 Photos</option>
      <option value="3">3 Photos</option>
      <option value="4">4 Photos</option>
      <option value="5">5 Photos</option>
      <option value="6">6 Photos</option>
      <option value="7">7 Photos</option>
      <option value="8">8 Photos</option>
      <option value="9">9 Photos</option>
      <option value="10">10 Photos</option>
    </select>
    </div>
    </form>
    
    </body>
    </html>
    coothead

  3. #3
    Join Date
    Jan 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Absolute, bang on! .. that just saved big time.. thank you very much!

  4. #4
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    No problem, you're welcome.

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
  •