Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   Динамические создание полей ввода и заполнение их данными (https://javascript.ru/forum/events/3211-dinamicheskie-sozdanie-polejj-vvoda-i-zapolnenie-ikh-dannymi.html)

vitasya 29.03.2009 16:52

Динамические создание полей ввода и заполнение их данными
 
Добрый день всем! Есть проблема, нужна ваша помощь. Надо следать форму (или неодну), где есть 2 поля : логин и пароль. также есть кнопки добавить/удалить поля ввода и кнопка генерирования логина/пароля. Как добиться того, чтобы генерировать логин/пароль во всех полях ввода? (т.е. проблема в том, что не могу получить доступ к новым полям).
Идеально было б иметь массив из созданных полей и потом передать в ф-ю генерирования.
ф-я создания полей:
function addline()
{
var form_generate_login_password = getId("form_generate_login_password");

var account = new Array();
account[count] = document.createElement("div");
account[count].setAttribute("name","account["+count+"]");
account[count].setAttribute("id","account["+count+"]");

var new_input_login = document.createElement("input");
new_input_login.setAttribute("type","text");
new_input_login.setAttribute("class","input_text") ;
new_input_login.setAttribute("name","login["+count+"]");
new_input_login.setAttribute("id","login["+count+"]");
account[count].appendChild(new_input_login);

var new_separator = document.createElement("b");
var new_separator_text = document.createTextNode("\u0020:\u0020");
new_separator.appendChild(new_separator_text);
account[count].appendChild(new_separator);

var new_input_password = document.createElement("input");
new_input_password.setAttribute("type","password") ;
new_input_password.setAttribute("class","input_tex t");
new_input_password.setAttribute("name","password["+count+"]");
new_input_password.setAttribute("id","password["+count+"]");
account[count].appendChild(new_input_password);
account[count].innerHTML += "<br />";

account.push(account[count].id);
form_generate_login_password.appendChild(account[count]);
count++;}

Заранее спасибо.

x-yuri 29.03.2009 23:47

можно, например, назначать класс(ы) элементам, по которым в дальнейшем их находить

p.s. не вижу для такого количества w3c в коде, тем более, что используется и innerHTML. С последним все было бы читабельнее (имхо), вполне себе кроссбраузерно и он скорее всего будет в html 5

x-yuri 29.03.2009 23:51

p.p.s. в атрибуте id нельзя использовать '[', ']':
тип id: ID (http://www.w3.org/TR/html401/types.html#type-id)
name: CDATA (http://www.w3.org/TR/html401/types.html#type-cdata)


Часовой пояс GMT +3, время: 17:59.