Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]dynamicznie wstawiany select
island
post
Post #1





Grupa: Zarejestrowani
Postów: 67
Pomógł: 1
Dołączył: 7.09.2008

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


Chciałbym się dowiedzieć jak przerobić ten kod by móc dodawać pole select za pomocą JavyScript.

CODE

var element1 = document.createElement('input');
element1.setAttribute('type', 'text');
element1.setAttribute('name', "pole_tekstowe");
element1.setAttribute('size', 40);
document.getElementById("pole").appendChild(element1);
Go to the top of the page
+Quote Post
darko
post
Post #2





Grupa: Zarejestrowani
Postów: 2 885
Pomógł: 463
Dołączył: 3.10.2009
Skąd: Wrocław

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


  1. var names = new Array('opcja1', 'opcja2', 'opcja3');
  2. var values = new Array(1, 2, 3);
  3. var select1 = document.createElement('select');
  4. select1.setAttribute('name', "pole_select");
  5. for(var i=0; i < names.length; i++)
  6. {
  7. var tmp = document.createElement('option');
  8. tmp.appendChild(document.createTextNode(names[i]));
  9. tmp.value = values[i];
  10. select1.appendChild(tmp);
  11. }
  12. //document.getElementById('pole').appendChild(select1);
  13. document.body.appendChild(select1);
  14. </body></html>


Ten post edytował darko 4.05.2010, 14:02:05
Go to the top of the page
+Quote Post
island
post
Post #3





Grupa: Zarejestrowani
Postów: 67
Pomógł: 1
Dołączył: 7.09.2008

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


Dzięki za odpowiedź(IMG:style_emoticons/default/smile.gif)
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: 23.08.2025 - 04:56