How do I attach links to individual array items?

umtek12

I have been working for hours trying to get this to work. What I want to do is to: First, have two drop down menu, first one controlling the second. Then I want to be able to link each individual "second-selection" to a href. However, the "second-selections" are in an array and I do not know how to access them into html. Please help.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Any Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <script type="text/javascript">

        var firmwares = [];
        firmwares[1] = ["Sacramento","San Diego","San Francisco","Los Angeles"];
        firmwares[2] = ["Cleveland","Akron","Canton","Cincinnati","Columbus"];
        firmwares[3] = ["Philadelphia","Pittsburgh","Harrisburgh"];
        firmwares[4] = [];

        function fillSelect(nValue,nList){

            nList.options.length = 1;
            var curr = firmwares[nValue];
            for (each in curr)
                {
                 var nOption = document.createElement('option');
                 nOption.appendChild(document.createTextNode(curr[each]));
                 nOption.setAttribute("value",curr[each]);           
                 nList.appendChild(nOption);
                }
        }
    </script>

    </head>
    <body>
        <form method="post" action="">
           <div>
                <select name='phones' onchange="fillSelect(this.value,this.form['firmwares'])">
                    <option value="">Select Your State</option>
                    <option value="1">California</option>
                    <option value="2">Ohio</option>
                    <option value="3">Pennsylvania</option>
                    <option value="4">Alaska</option>
                </select>
                <select name='firmwares' >
                    <option value="">Select Your City</option>
                </select>
           </div>
        </form>
    </body>
    </html>
Cary

Try this

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Any Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">

    var firmwares = {};
    firmwares[1] = {"Sacramento" : "http://www.abc.com",
                    "San Diego" : "http://www.abc.com",
                    "San Francisco" : "http://www.abc.com",
                    "Los Angeles" : "http://www.abc.com"};
    firmwares[2] = {"Cleveland" : "http://www.abc.com",
                    "Akron" : "http://www.abc.com",
                    "Canton" : "http://www.abc.com",
                    "Cincinnati" : "http://www.abc.com",
                    "Columbus" : "http://www.abc.com"};
    firmwares[3] = {"Philadelphia" : "http://www.abc.com",
                    "Pittsburgh" : "http://www.abc.com",
                    "Harrisburgh" : "http://www.abc.com"};
    firmwares[4] = {};

    function fillSelect(nValue,nList){

        nList.options.length = 1;
        var curr = firmwares[nValue];
        for (each in curr)
            {
             var nOption = document.createElement('option');
             nOption.appendChild(document.createTextNode(each));
             nOption.setAttribute("value",each);           
             nList.appendChild(nOption);
            }

        document.getElementById("gotoCity").style.display = "none";
    }

    function openCity(firmware, city) {
        var gotoCity = document.getElementById("gotoCity");
        gotoCity.href = firmwares[firmware][city];
        gotoCity.style.display="";
    }
</script>

</head>
<body>
    <form method="post" action="">
       <div>
            <select name='phones' onchange="fillSelect(this.value,this.form['firmwares'])">
                <option value="">Select Your State</option>
                <option value="1">California</option>
                <option value="2">Ohio</option>
                <option value="3">Pennsylvania</option>
                <option value="4">Alaska</option>
            </select>
            <select name='firmwares' onchange="openCity(this.form['phones'].value, this.value)" >
                <option value="">Select Your City</option>
            </select>
            <a id="gotoCity" href="#" style="display:none;">Go</href>
       </div>
    </form>
</body>
</html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I attach links to individual array items?

From Dev

How do I push individual array items into another array with PHP?

From Dev

stdClass obj array .. how to print individual items?

From Dev

How do I find out if individual items in CheckedListBox are checked? C#

From Dev

how do I prevent my list items from being broken up into individual strings when writing to CSV?

From Dev

How do I filter a typescript array with items in another array

From Dev

How do I determine the number of items I have stored in an array?

From Dev

How do I associate individual buttons with individual divs?

From Dev

How do I attach optional attributes to values?

From Dev

How do I attach to a process in Eclipse?

From Dev

How do I attach a listener to a cloned element?

From Dev

How do I attach a listener to a cloned element?

From Dev

How do I attach a variable to a QTextEdit control

From Dev

How do I attach a terminal to a detached process?

From Dev

How to return individual array items from a constructor function

From Dev

How do I nest an array of items dividing them by their first value?

From Dev

How do I count the number of items in an array that start with the highest number?

From Dev

How do I safely remove items from an array in a for loop?

From Dev

How do I make each of the list items in an array clickable?

From Dev

How do I remove/filter specific items from an array?

From Dev

How do i group items by key in a multi dimension array with php

From Dev

How do I access the index of items inside an array that is inside a dictionary?

From Dev

How do I filter multiple items from an array and add to an object?

From Dev

Sencha: How do I add items to carousel using array

From Dev

How do I nest an array of items dividing them by their first value?

From Dev

How do I count the number of items in an array that start with the highest number?

From Dev

How do I make each of the list items in an array clickable?

From Dev

How do i find the the total items stored in an array variable in Elasticsearch

From Dev

How do I print all array items on one line?

Related Related

  1. 1

    How do I attach links to individual array items?

  2. 2

    How do I push individual array items into another array with PHP?

  3. 3

    stdClass obj array .. how to print individual items?

  4. 4

    How do I find out if individual items in CheckedListBox are checked? C#

  5. 5

    how do I prevent my list items from being broken up into individual strings when writing to CSV?

  6. 6

    How do I filter a typescript array with items in another array

  7. 7

    How do I determine the number of items I have stored in an array?

  8. 8

    How do I associate individual buttons with individual divs?

  9. 9

    How do I attach optional attributes to values?

  10. 10

    How do I attach to a process in Eclipse?

  11. 11

    How do I attach a listener to a cloned element?

  12. 12

    How do I attach a listener to a cloned element?

  13. 13

    How do I attach a variable to a QTextEdit control

  14. 14

    How do I attach a terminal to a detached process?

  15. 15

    How to return individual array items from a constructor function

  16. 16

    How do I nest an array of items dividing them by their first value?

  17. 17

    How do I count the number of items in an array that start with the highest number?

  18. 18

    How do I safely remove items from an array in a for loop?

  19. 19

    How do I make each of the list items in an array clickable?

  20. 20

    How do I remove/filter specific items from an array?

  21. 21

    How do i group items by key in a multi dimension array with php

  22. 22

    How do I access the index of items inside an array that is inside a dictionary?

  23. 23

    How do I filter multiple items from an array and add to an object?

  24. 24

    Sencha: How do I add items to carousel using array

  25. 25

    How do I nest an array of items dividing them by their first value?

  26. 26

    How do I count the number of items in an array that start with the highest number?

  27. 27

    How do I make each of the list items in an array clickable?

  28. 28

    How do i find the the total items stored in an array variable in Elasticsearch

  29. 29

    How do I print all array items on one line?

HotTag

Archive