Names of input fields: why call it by name []?

As I am still trying to solve my other problem (need help here !), I am learning how to name form elements that are the same but on different lines.

Following this example here , the author of the article named his text fields "input_box_one". The jQuery function that he wrote also duplicates input fields with the same name. I would like to know the reason for naming its text fields, and how does the script server that it is going to write collect input from text fields that are also called?

I am going to write in classic ASP.

<table id = "options-table"> <tr> <td>Input-Box-One</td> <td>Input-Box-Two</td> <td>&nbsp;</td> </tr> <tr> <td><input type = "text" name = "input_box_one[]" /></td> <td><input type = "text" name = "input_box_two[]" /></td> <td><input type = "button" class = "del" value = "Delete" /></td> </tr> <tr> <td><input type = "text" name = "input_box_one[]" /></td> <td><input type = "text" name = "input_box_two[]" /></td> <td><input type = "button" class = "add" value = "Add More" /></td> </tr> </table> 

Thanks!

+4
source share
3 answers

In ASP Classic, Request.Form("someName") returns an object that implements the IStringList interface. This interface has two members, Item([i]]) , which is the default property and Count .

You must remove the suffixes [] if you are sending to ASP. You can access multiple values ​​that use the same name using the optional indexer parameter i . For instance.

  Dim someValue : someValue = Request.Form("someName")(2) 

I can't remember if this collection is based on 0 or 1, but it should be easy for you to check. An object may also support For Each , but this may not be as useful in your scenario.

+6
source

[] is PHPism. This causes the PHP parser to express the data in $_POST['fieldname'] or $_GET['fieldname'] as an array.

PHP is the only language I know where a standard HTML form data analyzer requires special names in the data to switch between scalar and massive modes.

+4
source

Multiple input fields with the same name will be represented as comma-separated values ​​under the name attribute in the classic ASP.

So,

 <input type="text" name="input_box_one[]" value="foo" /> <input type="text" name="input_box_one[]" value="bar" /> 

in form after submission in classic ASP, request.form("input_box_one[]")

will provide you with:

"foo,bar"

0
source

All Articles