![]() |
![]() |
![]()
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: Przyjaciele php.pl Postów: 1 595 Pomógł: 282 Dołączył: 24.09.2007 Skąd: Reda, Pomorskie. Ostrzeżenie: (0%) ![]() ![]() |
nie zrozumiałeś mnie... nie pytałem się JAK wstawiasz objLetKnow tylko GDZIE
a konkretnie, PRZED czy PO linijce: objLetKnowButton.onclick = function(){alert(document.letknowform.nadawca.value); return false;} ![]() -------------------- - Oh no, my young coder. You will find that it is you who are mistaken, about a great many things... - |
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 184 Pomógł: 13 Dołączył: 7.01.2008 Ostrzeżenie: (0%) ![]() ![]() |
nie zrozumiałeś mnie... nie pytałem się JAK wstawiasz objLetKnow tylko GDZIE a konkretnie, PRZED czy PO linijce: objLetKnowButton.onclick = function(){alert(document.letknowform.nadawca.value); return false;} ![]() Przed. Skrypt najpierw tworzy opakowanie div o id="letknow", następnie tworzony jest formularz i wstawiane do niego pola input. Linijka o którą pytasz jest ostatnia (w zasadzie przedostatnia) z całego skryptu. Poniżej cała funkcją tworząca formularz: Kod function letKnowCreate(){ var objBody = document.getElementsByTagName("body").item(0); //Opakowanie var objLetKnow = document.createElement('div'); objLetKnow.setAttribute('id','letknow'); objLetKnow.style.display = 'none'; objBody.appendChild(objLetKnow); //Close button var objLetKnowClose = document.createElement('a'); objLetKnowClose.setAttribute('href','#'); objLetKnowClose.setAttribute('id','close'); objLetKnowClose.onclick = function () {letKnowClose(); return false;} objLetKnowClose.setAttribute('title','zamknij'); objLetKnowClose.innerHTML = "x"; objLetKnow.appendChild(objLetKnowClose); //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('id','letknow1'); //ROZWIAZANIE ZASTĘPCZE objLetKnowNadawca.setAttribute('value','Twój e-mail'); objLetKnowNadawca.onfocus = function () {if(this.value=='Twój e-mail' || this.value=='Nieprawidłowy e-mail!') this.value=''} objLetKnowForm.appendChild(objLetKnowNadawca); //Input adresat var objLetKnowAdresat = document.createElement('input'); objLetKnowAdresat.setAttribute('type','text'); objLetKnowAdresat.setAttribute('name','adresat'); objLetKnowAdresat.setAttribute('id','letknow2'); //ROZWIAZANIE ZASTĘPCZE objLetKnowAdresat.setAttribute('value','E-mail znajomego'); objLetKnowAdresat.onfocus = function () {if(this.value=='E-mail znajomego' || this.value=='Nieprawidłowy e-mail!') this.value=''} objLetKnowForm.appendChild(objLetKnowAdresat); //Input button var objLetKnowButton = document.createElement('input'); objLetKnowButton.setAttribute('type','submit'); objLetKnowButton.setAttribute('name','letknowbutton'); objLetKnowButton.setAttribute('value','Powiadom'); objLetKnowButton.setAttribute('id','letknow3'); //ROZWIAZANIE ZASTĘPCZE objLetKnowButton.onclick = function(){sendLetKnow(document.getElementById('letknow1').value,document.getElementById('letknow2').value); return false;} //LINIJKA ZMIENIONA, DOSTOSOWANA DO ROZWIĄZANIA ZASTĘPCZEGO objLetKnowForm.appendChild(objLetKnowButton); } Jak widać zmieniłem skrypt, teraz korzysta z ID pól input, a nie z atrybutów NAME. Ten post edytował windman 20.06.2008, 12:22:42 |
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 14.08.2025 - 21:00 |