php - how to populate the second drop down using the selected value in first drop down? -


Say I have two drop-doses that are populated during my JSP load

  & Lt; Id = "group" name = "group" & gt; Select - First Drop Down & lt; Option value = "0001" & gt; 1 & lt; / Options & gt; & Lt; Option value = "0002" & gt; 2 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Select ID = "Sub Group" name = "square" & gt; - Second drop down & lt; Option value = "0001-000"> A & lt; / Option & gt; - Option Price 001 & lt; Option value = "0001-010" & gt; B & lt; / Option & gt; Sub group associated with & lt; Option value = "0001-020" & gt; C & lt; / Option & gt; & Lt; Option value = "0001-030" & gt; D & lt; / Options & gt; & Lt; Option value = "0001-040" & gt; E / option & gt; & Lt; Option value = "0002-000"> F. & lt; / Options & gt; - Sub-group associated with option price 002 & lt; Option value = "0002-010" & gt; G & lt; / Option & gt; & Lt; Option value = "0002-020" & gt; H & lt; / Options & gt; & Lt; Option value = "0002-040" & gt; I & lt; / Options & gt; & Lt; / Select & gt;  

Now I'll have to filter the second drop down based on the value selected in the first drop down. I can not use PHP code which uses DB callback methods I have something like this in my script.

  $ ("# group"). Change (function () {var groupVal = $ (this) .find ("option: selected"). Val (); $ ('# subGroup option'). Filter (function ({return! $ (This) .val ( ) IndexOf (groupVal)! = - 1);}). Remove ();}); The script is working fine, it removes all other options, then selected one but my problem is that the next time I select the second value in the first drop down , The second drop down becomes empty I have also worked with hide / show but I think they will be  and  select & gt;  

">

If you are removing the elements, then you are not getting them back. Use the Hide () and Show () as you suggest yourself Given:

  $ ("# group"). Change (function () {var groupVal = $ (this) .find ("option: selected"). Val (); $ ( '# SubGroup Options') Hide (); $ ('# subGroup option [value ^ =' + groupVal + ']'). Show ();});  

Every time When # group is selected If X changes, Hide all the options in #subGroup and only show people whose value attribute starts with groupVal . < / P>


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -