Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Czyszczenie formularza z pominięciem pól zablokowanych
Meferot
post
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 31.08.2009

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


Nie wiem jak dodać do tego skryptu:
  1. function clearForm(form) {
  2. $(':input', form).each(function() {
  3. var type = this.type;
  4. var tag = this.tagName.toLowerCase();
  5. if (type == 'text' || type == 'password' || tag == 'textarea')
  6. this.value = "";
  7. else if (type == 'checkbox' || type == 'radio')
  8. this.checked = false;
  9. else if (tag == 'select')
  10. this.selectedIndex = -1;
  11. });
  12. };

Opcję, która będzie pomijać pola zablokowane (disbaled).
Pomoże ktoś? ;d
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
toel
post
Post #2





Grupa: Zarejestrowani
Postów: 97
Pomógł: 11
Dołączył: 2.02.2010

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


.attr()

I sprawdzasz atrybut disabled, readonly, czy coś :]
Go to the top of the page
+Quote Post
Meferot
post
Post #3





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 31.08.2009

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


Zrobiłem tak jak mówiłeś, ale gdzieś musi być błąd bo skrypt nie działa:
  1. function clearForm(form) {
  2. $(':input', form).each(function() {
  3. var type = this.type;
  4. var tag = this.tagName.toLowerCase();
  5. var disabled = this.attr("disabled");
  6. if (type == 'text' || type == 'password' || tag == 'textarea') {
  7. if (disabled != 'disabled')
  8. this.value = "";
  9. }
  10. else if (type == 'checkbox' || type == 'radio')
  11. this.checked = false;
  12. else if (tag == 'select')
  13. this.selectedIndex = -1;
  14. });
  15. };


Ten post edytował Meferot 19.01.2011, 19:08:36
Go to the top of the page
+Quote Post
toel
post
Post #4





Grupa: Zarejestrowani
Postów: 97
Pomógł: 11
Dołączył: 2.02.2010

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


  1. var disabled = this.attr("disabled");


wg mnie dlatego, że mieszasz metodę jQuery ze zwykłym obiektem JS. Przepisz sobie cały ten skrypt na jQuery, żeby ujednolicić zapis.
Go to the top of the page
+Quote Post
Crozin
post
Post #5





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

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


jQuery obsługuje selektory :not() oraz :disabled, więc wystarczy stworzyć następujący selektor:
Kod
:input:not(:disabled)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 20.08.2025 - 20:38