Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input Box Names: Why name it with a [ ]?

As I'm still trying to resolve my other issue (need some help here!), I'm exploring on how to name form elements which are the same, but on different rows.

Following this example here, the author of the article named his textboxes to be "input_box_one". The jQuery function he has written also duplicates the input boxes to have the same name. I would like to know the reason for naming his textboxes like that, and how does the server script he is going to write collect the input from textboxes which are similarly named?

I'm going to be writing 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!

like image 882
kosherjellyfish Avatar asked Dec 26 '22 23:12

kosherjellyfish


1 Answers

In ASP Classic the 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 should remove the [] suffixes if you are posting to ASP. You can access multiple values that use the same name using the additional indexer parameter i. E.g.

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

I can't remember if this collection is 0 or 1 based but should be easy for you to test. The object may also support For Each as well but that may not be that useful in your scenario.

like image 190
AnthonyWJones Avatar answered Jan 13 '23 14:01

AnthonyWJones