Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> select i options[].text
adax
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 24.02.2010

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


Witam

mam kod:
  1. var a = document.getElementById(nameselected1);
  2. var b = a.options[a.selectedIndex].text;
  3. alert (b);

wyswietla mi to aktualnie wybrany tekst z obiektu select... potrzebuje jednak tylko pierwszej litery z tego tekstu.
Probowalem czegos takiego:
  1. var a = document.getElementById(nameselected1);
  2. var b = a.options[a.selectedIndex].text[0];
  3. alert (b);

W firefoxie dziala - pokazuje mi tylko pierwsza litere, niestety w IE juz nie.
Czy ktos moze mnie nakierowac, jak powinien wygladac wlasciwy kod?

Pozdrawiam
Go to the top of the page
+Quote Post
kazikos
post
Post #2





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 1.03.2010

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


  1. var a = document.getElementById("a");
  2. var b = a.options[a.selectedIndex].value;
  3. var short_b = b.substring(0, 1);
  4.  
  5. alert(short_b);


Tylko musisz pamiętać by umieścić value w option.
Go to the top of the page
+Quote Post

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: 22.08.2025 - 17:56