Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Select i Option [js]
Forum PHP.pl > Forum > Przedszkole
Muadib
Mam pytanie dotyczące właściwości selecta i połączeniu go z javascript, powiedzmy że mam element select do którego dołączam javescript:

  1. <select name='stopien' onchange='if(this.selectedIndex == 0) { brak('other'); } else { widok('other');}'>
  2.  
  3. <option>marynarz</option>
  4. <option>oficer</option>
  5. <option>inne</option>
  6.  
  7.  
  8. <input type='text' name='inne' id='other' style='display:none;'>


Funkcja javovo scriptowa sie prezentuje następująco:

  1. function widok(obj)
  2. {
  3. document.getElementById(obj).style.display = '';
  4. }
  5.  
  6. function brak(obj)
  7. {
  8. document.getElementById(obj).style.display = 'none';
  9. }


Ogólnie ideą jest żeby po najechaniu na opcje inne wyświetlał sie input, tylko że jakoś sie buntuje ze nie chce :/
nitek
daje gotowca (niech nikt nie ma za złe) winksmiley.jpg

  1. function pokaz(obj1,obj2)
  2. {
  3. //alert(document.getElementById(obj).selectedIndex);
  4. if(document.getElementById(obj1).selectedIndex==2)
  5. document.getElementById(obj2).style.display = 'block';
  6. else
  7. document.getElementById(obj2).style.display = 'none';
  8. }
  9.  
  10. </head>
  11.  
  12.  
  13. <select name="stopien" id="stopien" onchange="javascript:pokaz('stopien','other');">
  14.  
  15. <option>marynarz</option>
  16. <option>oficer</option>
  17. <option>inne</option>
  18.  
  19.  
  20. <input type='text' name='inne' id='other' style='display:none;'>
  21.  
  22.  
  23. </body>
  24. </html>
Muadib
Dziękuje za poprawki biggrin.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.