Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> combo select, dynamiczna lista
usb
post
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 14.09.2006
Skąd: (War)(Saw)

Ostrzeżenie: (0%)
-----


WItam. Mam dla twardzieli twardy orzech do zgryzienia. Mam oto taki kod js:

  1. <script language="JavaScript" type="text/javascript">
  2. <!--
  3.  
  4. // first combo box
  5.  
  6. data_1 = new Option("1", "$");
  7. data_2 = new Option("2", "$$");
  8.  
  9. // second combo box
  10.  
  11. data_1_1 = new Option("11", "-");
  12. data_1_2 = new Option("12", "-");
  13. data_2_1 = new Option("21", "--");
  14. data_2_2 = new Option("22", "--");
  15. data_2_3 = new Option("23", "--");
  16. data_2_4 = new Option("24", "--");
  17. data_2_5 = new Option("25", "--");
  18.  
  19. // third combo box
  20.  
  21. data_1_1_1 = new Option("111", "*");
  22. data_1_1_2 = new Option("112", "*");
  23. data_1_1_3 = new Option("113", "*");
  24. data_1_2_1 = new Option("121", "*");
  25. data_1_2_2 = new Option("122", "*");
  26. data_1_2_3 = new Option("123", "*");
  27. data_1_2_4 = new Option("124", "*");
  28. data_2_1_1 = new Option("211", "**");
  29. data_2_1_2 = new Option("212", "**");
  30. data_2_2_1 = new Option("221", "**");
  31. data_2_2_2 = new Option("222", "**");
  32. data_2_3_1 = new Option("231", "***");
  33. data_2_3_2 = new Option("232", "***");
  34.  
  35. // fourth combo box
  36.  
  37. data_2_2_1_1 = new Option("2211","%")
  38. data_2_2_1_2 = new Option("2212","%%")
  39.  
  40. // other parameters
  41.  
  42. displaywhenempty=""
  43. valuewhenempty=-1
  44.  
  45. displaywhennotempty="-select-"
  46. valuewhennotempty=0
  47.  
  48.  
  49. function change(currentbox) {
  50. numb = currentbox.id.split("_");
  51. currentbox = numb[1];
  52.  
  53. i=parseInt(currentbox)+1
  54.  
  55. // I empty all combo boxes following the current one
  56.  
  57. while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
  58. (document.getElementById("combo_"+i)!=null)) {
  59. son = document.getElementById("combo_"+i);
  60. // I empty all options except the first one (it isn't allowed)
  61. for (m=son.options.length-1;m>0;m--) son.options[m]=null;
  62. // I reset the first option
  63. son.options[0]=new Option(displaywhenempty,valuewhenempty)
  64. i=i+1
  65. }
  66.  
  67.  
  68. // now I create the string with the "base" name ("stringa"), ie. "data_1_0"
  69. // to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill
  70.  
  71. stringa='data'
  72. i=0
  73. while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
  74. (document.getElementById("combo_"+i)!=null)) {
  75. eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex")
  76. if (i==currentbox) break;
  77. i=i+1
  78. }
  79.  
  80.  
  81. // filling the "son" combo (if exists)
  82.  
  83. following=parseInt(currentbox)+1
  84.  
  85. if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) &&
  86. (document.getElementById("combo_"+following)!=null)) {
  87. son = document.getElementById("combo_"+following);
  88. stringa=stringa+"_"
  89. i=0
  90. while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {
  91.  
  92. // if there are no options, I empty the first option of the "son" combo
  93. // otherwise I put "-select-" in it
  94.  
  95. if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
  96. if (eval("typeof("+stringa+"1)=='undefined'"))
  97. eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)")
  98. else
  99. eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)")
  100. else
  101. eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)")
  102. i=i+1
  103. }
  104. //son.focus()
  105. i=1
  106. combostatus=''
  107. cstatus=stringa.split("_")
  108. while (cstatus[i]!=null) {
  109. combostatus=combostatus+cstatus[i]
  110. i=i+1
  111. }
  112. return combostatus;
  113. }
  114. }
  115.  
  116. //-->
  117. </script>


Skrypt działą jak należy. Tzn. mamy pierwsza liste, wybieramy jakąś opcje i zależnie co wybralismy pojawiaja się nowe opcje w drugiej liście potem trzecia. Problem polega na tym jeżeli na stronie głownej mam zwykły tekst(linki z GETem) z wypisanymi głownymi kategoriami i po kliknieciu chcialbym zeby przeszla na strone z w/w kodem i odrazu zaznaczylo kat głowną z podporzadkowana do niej drugą listą.

Przesyłam dane np. w GET ale potem co? Jak zrobić żeby na dzień dobry bez kliknięć pokazało podrzedną listę wybranej wcześniej na stronie głownej kategorii.

Jakieś pomysły?

proszę przenieść wątek do działu po stronie przeglądarki

Ten post edytował usb 18.09.2009, 09:35:18
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.09.2025 - 04:25