【问题标题】:Dynamically Created Form Elements not submitting with form动态创建的表单元素未与表单一起提交
【发布时间】:2014-06-05 14:02:23
【问题描述】:

我使用 javascript 在表单中添加了一些输入类型元素。提交表单时,这些元素没有显示

var pos=document.getElementById(rid).rowIndex;
var new_row=document.getElementById("table1").insertRow(1+pos); 
new_row.id="newRow"+rowCount;
    var td5=new_row.insertCell(4);
    td5.align="left";
    td5.innerHTML="<textarea id=\"emailID\" name=\"emailID\" cols=\"40\" rows=\"5\" class=\"textbox\"></textarea>";

我也检查过

    var emailText=document.createElement("textarea");
    emailText.id='emailID';
    emailText.name='emailID',
    emailText.cols=40;
    emailText.rows=5;
    emailText.className="textbox";
    td5.appendChild(emailText);

提交时我检查了

alert(document.formName.emailID);

但这显示未定义。 谁能告诉我哪里错了?

【问题讨论】:

  • 试试这个form.appendChild(td5);,并请验证您在第一行传递的 ID。
  • 检查第一行的ID。因为在适当的地方插入了行
  • 它在这里工作。检查Sample Demo
  • 检查formName是否与动态创建的表单相同。
  • 是的,当我使用 document.getElementById('emailID');它正在工作,但当 document.formName.emailID 我必须通过 request.getParameter("emailID") 在 Action 上使用它时不起作用,并且必须在表单中添加它

标签: javascript jquery html forms jsp


【解决方案1】:

试试这样:

document.forms[0].elements["emailID"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    相关资源
    最近更新 更多