Form gets submitted Multiple times
Posted
by
rasika vijay
on Stack Overflow
See other posts from Stack Overflow
or by rasika vijay
Published on 2013-11-12T03:44:35Z
Indexed on
2013/11/12
3:53 UTC
Read the original article
Hit count: 194
While clicking inside the form , the form automatically tried to resubmit , I cannot figure out which part of the code causes it to behave like this . In the createTable function , a table is created after the domain is given . But I am unable to select any of the controls in the output . I have attached the jsfiddle code link here : http://jsfiddle.net/rasikaceg/S7kWM/
function createTable() {
document.getElementById("table_container").innerHTML = "";
var input_domain = document.forms["form1"]["DomainName"].value;
if (input_domain == null || input_domain == "") return;
var table = document.createElement("table"),
tablehead = document.createElement("thead"),
theadrow = document.createElement("tr"),
th1 = document.createElement("th"),
th2 = document.createElement("th"),
th3 = document.createElement("th"),
th4 = document.createElement("th");
th1.appendChild(document.createTextNode("Website"));
th2.appendChild(document.createTextNode("Enable/Disable Live Update for LM and CBD"));
th3.appendChild(document.createTextNode("From Date"));
th4.appendChild(document.createTextNode("To Date"));
theadrow.appendChild(th1);
theadrow.appendChild(th2);
theadrow.appendChild(th3);
theadrow.appendChild(th4);
tablehead.appendChild(theadrow);
table.appendChild(tablehead);
var names = ["website1", "website2"];
var container = document.getElementById("table_container");
var tablebody = document.createElement("tbody");
for (var i = 0, len = names.length; i < len; ++i) {
var row = document.createElement("tr"),
column1 = document.createElement("td"),
column2 = document.createElement("td"),
column3 = document.createElement("td"),
column4 = document.createElement("td"),
checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.name = names[i];
checkbox.value = names[i];
checkbox.id = names[i];
var label = document.createElement('label')
label.htmlFor = names[i];
label.appendChild(document.createTextNode(names[i]));
column1.appendChild(checkbox);
column1.appendChild(label);
var dropdown = document.createElement("select");
dropdown.name = names[i] + "_select";
var op1 = new Option();
op1.value = "enable";
op1.text = "enable";
var op2 = new Option();
op2.value = "disable";
op2.text = "disable";
dropdown.options.add(op1);
dropdown.options.add(op2);
column2.appendChild(dropdown);
var datetime_from = document.createElement('input');
datetime_from.type = "datetime-local";
datetime_from.name = names[i] + "_from";
column3.appendChild(datetime_from);
var datetime_to = document.createElement('input');
datetime_to.type = "datetime-local";
datetime_to.name = names[i] + "_to";
column4.appendChild(datetime_to);
row.appendChild(column1);
row.appendChild(column2);
row.appendChild(column3);
row.appendChild(column4);
tablebody.appendChild(row);
}
table.appendChild(tablebody);
document.getElementById("table_container").appendChild(table);
}
© Stack Overflow or respective owner