简体   繁体   中英

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. Those rows contain a number of input fields with id's and names that include the row number. I am adjusting those ids and names for the new row. 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.

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. 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. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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