简体   繁体   English

Javascript-动态添加的输入字段不可用

[英]Javascript - input fields added dynamically not available

I am using Javascript to add new rows to a table when an image is clicked in a classic ASP page. 在经典的ASP页面中单击图像时,我使用Javascript向表中添加新行。 Those rows contain a number of input fields with id's and names that include the row number. 这些行包含许多带有ID的输入字段,名称包括行号。 I am adjusting those ids and names for the new row. 我正在为新行调整这些ID和名称。 The operation is visibly working and the new row appears at the bottom of the table where I wanted to put it. 该操作明显正常,并且新行显示在我要放置表格的底部。 Also, if I select the new row then view selected source in Firefox, I can see the new row's HTML with id's & names as expected. 另外,如果我选择新行,然后在Firefox中查看选定的源,则可以看到新行的HTML,其ID和名称均符合预期。

When I submit the form, however, the new fields are not availabe and the loop below does not report them: 但是,当我提交表单时,新字段不可用,并且下面的循环不报告它们:

dim sItem
For Each sItem In Request.Form
  Response.Write(sItem)
  Response.Write(" - [" & Request.Form(sItem) & "]<br>")
Next

I am no Javascript whizz and have no idea why this might not be working. 我不是Java语言专家,也不知道为什么这可能无法正常工作。 Any help would be appreciated. 任何帮助,将不胜感激。

I know you've worked it out now, but just thought I'd write up my comment for future visitors (and hopefully some points too?!) 我知道您已经解决了这个问题,但是只是想为将来的访问者写些评论(希望还有一些要点?!)

To ensure all the input fields you want are submitted with the form, they must be enclosed inside the <form> tags. 为了确保您想要的所有输入字段都与表单一起提交,必须将它们包含在<form>标记内。 eg 例如

<html>
<body>
<form id="myForm" action="fooPage.asp" method="post">

    <!-- These two input fields will be submitted to fooPage.asp -->
    <input type="hidden" name="myhiddenField1" value="123" />
    <input type="text" name="myTextField1" value="hello world" />
    <input type="submit" value="Submit myForm" />
</form>

<!-- These two input fields won't be submitted to fooPage.asp -->    
<input type="hidden" name="myhiddenField2" value="456" />
<input type="text" name="myTextField2" value="hello world 2" />

</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM