how to set form attribute on a createElement input with Javascript

Manatax picture Manatax · Jul 1, 2012 · Viewed 9.2k times · Source

can someone please help me out? I'm trying to create an input dynamically with this function, but the "form" attribute is not being set.

function addInput(parentID,inputNAME) {
    var padre = document.getElementById(parentID);
    var container = document.createElement("input");
    container.type = "text";
    container.name = inputNAME;
    container.value = "";
    container.form = 'extra';
    var enter = document.createElement("br");
    padre.appendChild(container);
    padre.appendChild(enter);
}

I've also tried with this:

container.formName = 'extra';
container['form'] = 'extra';
container.attributes['form'] = 'extra';
container.createAttribute('form','extra')

EDIT:
Answer:
container.setAttribute("Form",'extra');

Answer

Manatax picture Manatax · Jul 2, 2012

I've used

container.setAttribute("Form",'extra');

and it appears to be working in FF, Chrome and Opera.