Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> lista.selectedIndex nie przyjmuje wartości -1
php programmer
post
Post #1





Grupa: Zarejestrowani
Postów: 1 045
Pomógł: 5
Dołączył: 8.11.2004
Skąd: trójmiasto

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


Mam problem.
Mam SELECT "lista"
Kod
var lista = document.getElementById("lista");
alert(lista.selectedIndex);

gdy jest zanzaczony jakiś element to jest OK
ale jak nie mam zaznaczonego elementu to nic mi nie wyświetla
a liczyłem na to że będę miał -1 wtedy mógbym odpowiednio reagować
na brak wybrania jakiegokolwiek elementu.
Skoro nie przyjmuje wartości -1 to jak poznać że nie wybrano niczego.

Ten post edytował php programmer 1.09.2005, 09:20:34
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




nasmazylem taki kod: jest ok. powiedz co się chrzni i kiedy:
  1. <script language="javascript">
  2. function Dodaj(){
  3. var source = document.getElementById("filmy");
  4. var dest = document.getElementById("lista");
  5. dest.options[dest.length] = new Option(source.options[source.selectedIndex].text,source.options[source.selectedInd
    ex].value);
  6. //AktualizujPosta();
  7. }
  8.  
  9. function Usun(){
  10. document.getElementById("lista").remove(document.getElementById("lista").selectedIndex);
  11. //AktualizujPosta();
  12. }
  13.  
  14. function Odtwarzaj(){
  15. var lista = document.getElementById("lista");
  16. if ((!lista.selectedIndex || lista.selectedIndex == -1) && lista.selectedIndex != 0)
  17. alert('zaznacz cos : ' + lista.selectedIndex);
  18. else
  19. alert('zaznaczone : ' + lista.selectedIndex);
  20. //var link = lista.options[lista.selectedIndex].value;
  21. //if (link=='') alert('Ten tytuł nie ma przypisanego pliku filmowego');
  22. //else location.href = link;
  23. //alert(lista.selectedIndex)
  24.  
  25. }</script>
  26.  
  27. <select id="lista">
  28. <select id="filmy">
  29. <option value="fil1">fil1</option>
  30. <option value="fil2">fil2</option>
  31. <option value="fil3">fil3</option>
  32.  
  33. <input type="button" onclick="Dodaj();" value="Dodaj" />
  34. <input type="button" onclick="Odtwarzaj();" value="Odtwarzaj"/>
  35. <input type="button" onclick="Usun();" value="Usun"/>


i zacznij wreszcie bbcode uzywac!!!
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: 5.10.2025 - 02:35