how to make dynamic select box

Discussion in 'PHP' started by dineshsingh1984, Jan 13, 2011.

  1. #1
    how to make two select box one for states of india and second for districts of individual state
    when select one state in second select box display district only this state for example if i select uttar pradesh in first select box then another select box display district only uttar pradesh

    plz help me...........
     
    dineshsingh1984, Jan 13, 2011 IP
  2. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #2
    Sounds like something for javascript.
     
    ssmm987, Jan 13, 2011 IP
  3. domainwink

    domainwink Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Check out jQuery. It might help you.
     
    domainwink, Jan 13, 2011 IP
  4. dineshsingh1984

    dineshsingh1984 Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    plz tell me javascript function which are use for this query........
     
    dineshsingh1984, Jan 14, 2011 IP
  5. kokulusilgi

    kokulusilgi Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    <script>
    var States = new Array(); 
    States[1]=["1 SubState 1","1 SubState 2", "1 SubState 3"];
    States[2]=["2 SubState 1","2 SubState 2"];
    States[3]=["3 SubState 1","3 SubState 2", "3 SubState 3", "3 SubState 4"];
    function selectState(stateId)
    {
    	subSelectOptions = '';
    	selectedState = States[stateId];
    	for (x in selectedState)
    	{
    		subSelectOptions += '<option value="'+selectedState[x]+'">'+selectedState[x]+'</option>';
    	}
    	document.getElementById('substate').innerHTML = subSelectOptions;
    }
    </script>
    State: <select name="state" id="state" onchange="selectState(this.value);">
    <option value="1">State 1</option>
    <option value="2">State 2</option>
    <option value="3">State 3</option>
    </select><br /><br />
    Sub State: <select name="substate" id="substate">
    <option value="0">Select State Before</option>
    </select>
    
    HTML:
     
    kokulusilgi, Jan 14, 2011 IP
  6. dineshsingh1984

    dineshsingh1984 Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    thanks kokulusilgi,
    nice and it's working but i am fetch state table and district table from mysql database because its very large database near about 35 state in state table and 965 district in district table then how can make select box sorry because in my first query i do not mention this condition

    once again thanks
    but plz tell me for this type.............
     
    dineshsingh1984, Jan 14, 2011 IP
  7. kokulusilgi

    kokulusilgi Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    you can use jquery.

    and your script returns json state data. and then edit my script.
     
    kokulusilgi, Jan 15, 2011 IP
  8. dineshsingh1984

    dineshsingh1984 Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #8
    thanks,
    I will try...........
     
    dineshsingh1984, Jan 16, 2011 IP