www.webdeveloper.com
Results 1 to 3 of 3

Thread: Changing URL based on Country drop down list

  1. #1
    Join Date
    Jul 2008
    Posts
    93

    Changing URL based on Country drop down list

    Hi All,

    Does anyone have a script handy where based on the country selected from a drop down list, a URL at the bottom of the page can be changed?

    This is the web form I'm working on https://forms.bd.com/askbd/index.sp

    The link that needs to change based on country selection is the "Privacy Statement and Consent to Use of Data". Basically, if an Asian country is selected, it'll change to Asia's privacy policy. If a European country is selected, the link will change to Europe's privacy policy, etc....

    Thanks in advance.

  2. #2
    Join Date
    Sep 2011
    Location
    Bristol, England, United Kingdom
    Posts
    192
    I was able to come up with this working example. It might not be the best, but it works. I'm sure others could write you a more comprehensive piece of code.

    PHP Code:
    <!DOCTYPE html>

    <
    select id="continents">
        <
    optgroup label="continents">
            <
    option id="1">Asia</option>
            <
    option id="2">Africa</option>
            <
    option id="3">EU</option>
        </
    optgroup>
    </
    select>

    <!-- Default 
    policy should be initialised here. -->
    <
    div id="privacy_policy"><a href="asiapolicy.html">Privacy Policy</a></div>

    <
    script type="text/javascript">

    document.getElementById("continents").addEventListener("change"changefalse);

    function 
    change()
    {
        
    // Get ID of selected <option>.
        
    var id document.getElementById("continents");
        var 
    id parseInt(id.options[id.selectedIndex].id);
        
        
    // 2D array to keep continents in.
        
    var continents = new Array(new Array());
        
        
    // HREF text. Not necessary but useful if links always the same name.
        
    var privacy "Privacy Policy";
        
        
    // Inisialise each elemennt to a new link.
        
    continents[0][0] = "<a href='/asia_policy.html'>"   privacy "</a>";
        
    continents[0][1] = "<a href='/africa_policy.html'>" privacy "</a>";
        
    continents[0][2] = "<a href='/eu_policy.html'>"     privacy "</a>";
        
        
    // Switch logic.
        
    switch(id)
        {
            case 
    1:
            {
                
    document.getElementById("privacy_policy").innerHTML continents[0][0];
                break;
            }
            
            case 
    2:
            {
                
    document.getElementById("privacy_policy").innerHTML continents[0][1];
                break;
            }
            
            case 
    3:
            {
                
    document.getElementById("privacy_policy").innerHTML continents[0][2];
                break;
            }
        }
    }

    </script> 
    Last edited by George88; 08-01-2012 at 05:41 PM.

  3. #3
    Join Date
    Jul 2008
    Posts
    93
    Thanks George. As long as it works!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles