SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    option box changing other box

    I am writing a script to give a weather forecast.

    I want the person to first chose the state, and then the city.

    The first box will list the states, the second will list the cities. How can I get the second box to just show the cities that match the state?
    Last edited by jkh1978; Oct 15, 2001 at 07:07.

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just fixed one of these up for a client of mine. Lets see if I can find that code and then you can cut and paste it...or at least figure it out.

    var arraySelect
    var trueDescription
    var sel
    var len
    function Option(desc,value){
    //properties of array
    this.desc=desc
    this.value=value
    }
    var select1=new Array(6)
    select1[0] = new Option("BRAIDED","5");
    select1[1] = new Option("CLASSIC","4");
    select1[2] = new Option("CLASSIC PQ!","200");
    select1[3] = new Option("DRAPED BUST","198");
    select1[4] = new Option("NO STEM CR 4","3");
    select1[5] = new Option("PL4 STEMLESS","199");
    var select2=new Array(18)
    select2[0] = new Option("BRAIDED","9");
    select2[1] = new Option("BRAIDED GEM!","10");
    select2[2] = new Option("BRAIDED N-3","203");
    select2[3] = new Option("BRONZE","13");
    select2[4] = new Option("CHAIN CENT","201");
    select2[5] = new Option("CORONET","7");
    select2[6] = new Option("CORONET PQ!","8");
    select2[7] = new Option("DOUBLE DIE","15");
    select2[8] = new Option("FLOWING HAIR","6");
    select2[9] = new Option("FLYING EAGLE","11");
    select2[10] = new Option("FUGIO ST UNI","2");
    select2[11] = new Option("INDIAN","12");
    select2[12] = new Option("INDIAN PQ!","206");
    select2[13] = new Option("INDIAN TY 1","205");
    select2[14] = new Option("INDIAN CN","204");
    select2[15] = new Option("LINCOLN","14");
    select2[16] = new Option("POINTED RAYS","1");
    select2[17] = new Option("SM DATE N-6","202");

    function descriptions(deno) {
    sel = document.addWishList.des
    var arraySelect=deno.value
    var len=eval(arraySelect+".length")
    for (var x=0;x<len;x++){
    sel.length=len+2
    sel.options[0].text="Any"
    sel.options[0].value=0
    sel.options[x+1].value=(eval(arraySelect+"["+x+"].value"))
    sel.options[x+1].text=(eval(arraySelect+"["+x+"].desc"))
    sel.options[len+1].text="None"
    sel.options[len+1].value=1
    }
    }

    The above goes into your head of course changing the array to your own standard.

    <form name="addWishList" method="post" action="">
    <select name="deno" id="deno" onchange="descriptions(deno)">
    <option value="select0">Any</option>

    <option value="select1">Large/Small Cent</option>

    <option value="select2">Half Cent</option>

    </select>
    <select name="des" id="des" onchange="alert(this.value)">
    <option value="0">Any</option>
    <option value="1">None</option>
    </select>
    </form>

    This part goes into the body...

    Hope that helps
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    could you give me the webpage so I could look at it also?

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi jkh1978,

    see the "Cascading Selects" scripts/tutorials at my site (GrassBlade). There are 2 versions; both demonstrate and discuss writing selection lists for what you are trying to do.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •