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.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Double Combo Drop Down menu in PHP

    Hi I have been searching a lot and no one seems to have the answer to this question so i figured Id try here. I am running a phpBB forum and I have successfuly modded it to ad a regular drop down menu for the profile field. I need a script though, that will allow my users to select a state and once the state is selected it loads a second drop down menu wich contains all the cities. There is a code on this site that does something similar to what i want but it is in javascript and I have tried unsucsessfuly to get the cities to load upon choosing a state. This code is used for opening up a link with the button go but i can do without the button

    <form name="doublecombo">
    <p><select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
    <option>Technology Sites</option>
    <option>News Sites</option>
    <option>Search Engines</option>
    </select>
    <select name="stage2" size="1">
    <option value="http://javascriptkit.com">JavaScript Kit</option>
    <option value="http://www.news.com">News.com</option>
    <option value="http://www.wired.com">Wired News</option>
    </select>
    <input type="button" name="test" value="Go!"
    onClick="go()">
    </p>

    <script>
    <!--

    /*
    Double Combo Script Credit
    By JavaScript Kit (www.javascriptkit.com)
    Over 200+ free JavaScripts here!
    */

    var groups=document.doublecombo.example.options.length
    var group=new Array(groups)
    for (i=0; i<groups; i++)
    group[i]=new Array()

    group[0][0]=new Option("JavaScript Kit","http://javascriptkit.com")
    group[0][1]=new Option("News.com","http://www.news.com")
    group[0][2]=new Option("Wired News","http://www.wired.com")

    group[1][0]=new Option("CNN","http://www.cnn.com")
    group[1][1]=new Option("ABC News","http://www.abcnews.com")

    group[2][0]=new Option("Hotbot","http://www.hotbot.com")
    group[2][1]=new Option("Infoseek","http://www.infoseek.com")
    group[2][2]=new Option("Excite","http://www.excite.com")
    group[2][3]=new Option("Lycos","http://www.lycos.com")

    var temp=document.doublecombo.stage2

    function redirect(x){
    for (m=temp.options.length-1;m>0;m--)
    temp.options[m]=null
    for (i=0;i<group[x].length;i++){
    temp.options[i]=new Option(group[x][i].text,group[x][i].value)
    }
    temp.options[0].selected=true
    }

    function go(){
    location=temp.options[temp.selectedIndex].value
    }
    //-->
    </script>

    </form>

    <p align="center"><font face="arial" size="-2">This free script provided by</font><br>
    <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
    Kit</a></font></p>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You would be better off with javascript to do this, if someone choose a wrong option, then they'd have to rechoose it and wait for the page to reload once again.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Las Vegas, NV - USA
    Posts
    104
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Are you sure the concept works for the customers using the form? To me, typing in LAS VEGAS is easier than scrolling down almost halfway through a drop down list of cities looking for my city. I can imagine the frustration of someone living in a state like California with hundreds of more cities than Nevada.

    Anyway, that's my thought. Sorry I could not be more helpful.
    Steven Sommers (blog)
    Shift4 Corporation -- www.shift4.com

    Creators of $$$ ON THE NET(tm) payment processing services.

  • #4
    New Coder
    Join Date
    Oct 2003
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have placed the java script code in a PHP form page but the thing is that the load function does not work...I am relatively new with PHP and Javascript and I cant seem to see why this is not working... a regular drop down menu works just fine but the double combo doesnt...I have no idea what to do

    I used to cities as an example but its specific places in cities really it's detailed so thats why I need this


  •  

    Posting Permissions

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