Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js] Dynamicznie tworzony formularz, Pod FF i Operą działa pod IE nie
windman
post
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
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nevt
post
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%)
-----


a gdzie wstawiasz objLetKnow do document (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
windman
post
Post #3





Grupa: Zarejestrowani
Postów: 184
Pomógł: 13
Dołączył: 7.01.2008

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


Cytat(nevt @ 19.06.2008, 22:07:32 ) *
a gdzie wstawiasz objLetKnow do document (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

objLetKnow jest tworzony w ten sam sposób, jest to div

Kod
var objLetKnow = document.createElement("div");
objLetKnow.setAttribute('id','letknow');
objLetKnow.style.display = 'none';
objBody.insertBefore(objLetKnow, objBody.firstChild);



Dodam, że dodałem do pola input nadawca atrybut id. I teraz działa: alert(document.getElementById('id_pola_nadawca').value);

ale to rozwiązanie awaryjne, powinno przecież też działać z this.form.nadawca.value

Ten post edytował windman 19.06.2008, 21:51:10
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: 8.10.2025 - 13:23