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.
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts
    Again, without enough information as to what it should look like, my mind reading skills suck!

    Show some work to comment upon.

  2. #17
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    7
    Thanked 0 Times in 0 Posts
    First of all, thanks for your patience.....

    When i say level options i mean this

    1st Level Options (Andalucía, Aragón, Asturias, Baleares)
    2nd level options (the ones in the array)

    The first thing i was looking for was a select list with 2 levels with an automatic generated link with a BaseURl + the name of the options, you solved it giving me this code:

    Works perfect, but i don't know how to make it to open the links in a new tab instead the same window, that's the only problem i have with that. Hope you can help me with that...

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <meta charset="utf-8" />
    <title> Untitled </title>
    
    <script type="text/javascript">
    
    // NOTE: You need to fill in the links as defined by your requirements in the following array elements
    var provincias = [
      [],  // spare (not used in this version of program)
      ['-','Almería',
           'Cádiz',
           'Córdoba',
           'Granada',
           'Huelva',
           'Jaén',
           'Málaga',
           'Sevilla'],
      ['-','Huesca',
           'Teruel',
           'Zaragoza'],
      ['-','Asturias'],
      ['-','Baleares']  // Note: no comma after final entry
    ];
    
    function cambiar(formulario){
      var i = 0;
      var select1 = formulario['D1'];
      var select2 = formulario['D2'];
      var vector = provincias[select1.selectedIndex];
      if(vector.length)select2.length=vector.length;
      var tarr = [];
      while(vector[i]){
        select2.options[i].value = vector[i]; // tarr[1];
        select2.options[i].text = vector[i];  // tarr[0];
        i++;
      }
      select2.options[0].selected = 1;
    }
    function goToSite(info) {
      if (info != '-') { alert(info); }                       // this line is for testing purposes only
    //  if (info != '-') { document.location.href = info; }   // uncomment this line after testing
    }
    
    function linkToSite(formulario) {
      var select1 = formulario['D1'];
      var select2 = formulario['D2'];
      var baseURL = 'http://www.codingforums.com/';  // defined as some common URL if same for all links
      var str = '';
      str = baseURL+select1.value+select2.value+'.html';
      goToSite(str); 
    }
    </script>
    
    <style type="text/css">
    
    </style>
    </head>
    <body>
    <form method="POST">
      <select name="D1" onchange="cambiar(this.form)">
      <option>-</option>
      <option>Andalucía</option>
      <option>Aragón</option>
      <option>Asturias</option>
      <option>Baleares</option>
      </select>
      <select name="D2" onchange="linkToSite(this.form)">
      </select></p>
    </form>
    </body>
    </html>
    Second

    I thought that it would be easy to me to modify the code and eliminate the second level options, to just keep 1 level option but with generating and taking me to the link with a "BaseUrl too + the option", in other words, the same thing that the code i post uo here but just for 1 level option, but i can't, and i don't post any code of that because i suck in javascript stuff..

    Thank you

  3. #18
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts
    For your 1st problem, look into: http://www.w3schools.com/jsref/met_win_open.asp
    That site shows you all the new window options available from javascript.

    Second part.
    Are you expecting for the level one option to do 2 different actions?
    Sometimes, it gives you only one link and another time it gives you a different link?
    If that is the case, then you need to define for me which links are controlled by which level at the time a selection is made.

    OR, are you asking for a SECOND drop down list that has only the first level and no sub-levels to control?

  4. Users who have thanked jmrker for this post:

    linkysnake (11-26-2012)

  5. #19
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    7
    Thanked 0 Times in 0 Posts
    The first problem is solved now...there's just a detail, Internet Explorer take me to the link, bur without adding the first level option to it, Any idea why it is working on Chrome but not in IE?


    Quote Originally Posted by jmrker View Post
    OR, are you asking for a SECOND drop down list that has only the first level and no sub-levels to control?
    Yes, i'm asking for another drop down list with only the first level and no sublevels (but with generated links "BaseUrl+Option")


    Thank You
    Last edited by linkysnake; 11-26-2012 at 04:25 PM.

  6. #20
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Lightbulb

    Add this to code...

    HTML:
    Code:
      <select name="D3" onchange="singleLinkToSite(this.form)">
      <option value='-'>-</option>
      <option value='Andalucia'>Andalucía</option>
      <option value='Aragon'>Aragón</option>
      <option value='Asturias'>Asturias</option>
      <option value='Baleares'>Baleares</option>
      </select>
      <p />
    JS:
    Code:
    function singleLinkToSite(formulario) {
      var select1 = formulario['D3'];
    
    // defined as some common URL if same for all links
      var baseURL = 'http://www.codingforums.com/';  
    // could be a 'global' variable if used in multiple functions
    
      var str = '';
      str = baseURL+select1.value+'.html';
      goToSite(str); 
    }

  7. Users who have thanked jmrker for this post:

    linkysnake (11-27-2012)

  8. #21
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    216
    Thanks
    0
    Thanked 29 Times in 27 Posts
    A good method to build a select menu is to use the Option() constructor for the select element.
    Code:
    new Option(text, value, defaultSelected, selected)
    See this page w3cshools.com page Changing Select element content on the fly.

  9. Users who have thanked 007julien for this post:

    linkysnake (11-27-2012)

  10. #22
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thank you, just 10 min before your post i was able to know how to modify the original code and adapt it to just one drop list


    You help me a lot and i learn so much things in these days, thank you for all your time and Help.

    Thank you too 007julien i will read that to see how it works


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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