![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 184 Pomógł: 13 Dołączył: 7.01.2008 Ostrzeżenie: (0%) ![]() ![]() |
Witam,
Tworzę formularz dynamicznie: Kod //formularz var objLetKnowForm = document.createElement("form"); objLetKnowForm.setAttribute('name','letknowform'); objLetKnowForm.setAttribute('method','get'); objLetKnowForm.onsubmit = function(){return false;} objLetKnow.appendChild(objLetKnowForm); //Input nadawca var objLetKnowNadawca = document.createElement("input"); objLetKnowNadawca.setAttribute('type','text'); objLetKnowNadawca.setAttribute('name','nadawca'); objLetKnowNadawca.setAttribute('value','Twój e-mail'); objLetKnowNadawca.onfocus = function () {if(this.value=='Twój e-mail') this.value=''} objLetKnowForm.appendChild(objLetKnowNadawca); //Input button var objLetKnowButton = document.createElement("input"); objLetKnowButton.setAttribute('type','submit'); objLetKnowButton.setAttribute('name','letknowbutton'); objLetKnowButton.setAttribute('value','Powiadom'); objLetKnowButton.onclick = function(){alert(document.letknowform.nadawca.value); return false;} objLetKnowForm.appendChild(objLetKnowButton); Pod FF i Operą alert zwraca zawartośc pola nadawca, natomiast IE wyświetla błąd: document.letknowform.nadawca jest pusty lub nie jest obiektem. Ktoś ma pomysł dlaczego? Pozdrawiam |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 207 Pomógł: 25 Dołączył: 16.11.2006 Ostrzeżenie: (0%) ![]() ![]() |
Nie nadużywaj tak setAttribute
Często są do tego właściwości obiektów/elementów. Np. el.setAttribute('type','submit'); => el.type='submit'; el.setAttribute('name','letknowbutton'); => el.name='letknowbutton'; el.setAttribute('value','Powiadom'); => el.value='Powiadom'; el.setAttribute('id','letknow3'); => el.id='letknow3'; to samo z title, href, method itp. itd. Oczywiście nie każdy element ma wszystkie te własności, np. <span> nie będzie miał .value czy .href, a input nie będzie miał .method Reszte obadaj sam. Gdyby nadal nie działało pod IE, to zamień var objBody = document.getElementsByTagName("body").item(0); na var objBody = document.getElementsByTagName("body")[0]; bo możliwe, że IE ma zbugowane HTMLCollection, jak wiele innych rzeczy. |
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 14.08.2025 - 16:45 |