Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JS] Wybór diva z listboxa.
Rewil
post
Post #1





Grupa: Zarejestrowani
Postów: 175
Pomógł: 0
Dołączył: 19.09.2009

Ostrzeżenie: (10%)
X----


Potrzebuję coś takiego uzyskać że jak wybiorę z listboxa jakąś wartość to w zależności od niej wyświetli mi innego diva.(Ukryje jednego, pokaze drugiego)
  1. <script type="text/javascript">
  2. function Pole(document.baner_form.elements['kamp_nazwa'].value) {
  3. if (document.baner_form.elements['kamp_nazwa'].value=="HTML"){
  4. document.getElementById(file_html).style.display = "block";
  5. document.getElementById(file_obra).style.display = "none";
  6. }else{
  7. document.getElementById(file_html).style.display = "none";
  8. document.getElementById(file_obra).style.display = "block";
  9. }
  10.  
  11. }
  12. </script>
  13. <div class="file_wgr">
  14. <div class="file_1">Rodzaj:
  15. <select name="kamp_nazwa[]" size="1" onChange="jump(this.form)">
  16. <option value="Obrazek">Obrazek</option>
  17. <option value="Flash">Flash</option>
  18. <option value="HTML">HTML</option>
  19. </select>
  20. </div>
  21. <div id="file_obra" class="file_2">
  22. Obrazek:
  23. <input type="hidden" name="MAX_FILE_SIZE" value="3145728000" />
  24. <input type="file" size="36" class="file" name="kamp_obrazek[]" />
  25. </div>
  26. <div id="file_html" class="file_2">
  27. Kod HTML:
  28. <textarea name="kamp_kod[]"></textarea>
  29. </div>
  30. </div>
  31.  

I tak jak w tym wypadku: Wybierze się HTML to pokaże się Kod HTML, lub jeśli obrazek to się pokaża Obrazek.
Odrazu mówię że JS to narazie dla mnie czarna magia ;/.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
yevaud
post
Post #2





Grupa: Zarejestrowani
Postów: 471
Pomógł: 89
Dołączył: 29.07.2008
Skąd: Warszawa

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


przede wszystkim getElementsByName
dlatego chcialem uzyc Name ze moze byc wiele elementow o tej samej nazwie na stronie, jesli dodajesz im indeksy to rownie dobrze moze byc to id

widze ze masz jquery, moze zamiast zwyklego javascript uzyjesz troche jego mocy ? (IMG:style_emoticons/default/smile.gif) poczytaj o selektorach w jquery

[JAVASCRIPT] pobierz, plaintext
  1. function Pole(element) {
  2. var container = $(element).parents('div.file_wgr');
  3. if (element.value=="HTML"){
  4. $('div.file_html', container).show();
  5. $('div.file_obra', container).hide();
  6. } else {
  7. $('div.file_html', container).hide();
  8. $('div.file_obra', container).show();
  9. }
  10. }
[JAVASCRIPT] pobierz, plaintext


  1. <div class="file_wgr">
  2. <div class="file_1">Rodzaj:
  3. <select name="kamp_nazwa[]" size="1" onChange="Pole(this)">
  4. <option value="Obrazek">Obrazek</option>
  5. <option value="Flash">Flash</option>
  6. <option value="HTML">HTML</option>
  7. </select>
  8. </div>
  9. <div class="file_obra" class="file_2">
  10. Obrazek:
  11. <input type="hidden" name="MAX_FILE_SIZE" value="3145728000" />
  12. <input type="file" size="36" class="file" name="kamp_obrazek[]" />
  13. </div>
  14. <div class="file_html" class="file_2">
  15. Kod HTML:
  16. <textarea name="kamp_kod[]""></textarea>
  17. </div>
  18. </div>


Ten post edytował yevaud 19.06.2010, 20:20:02
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: 12.10.2025 - 02:25