user2102316
user2102316

Reputation: 37

Trouble about input having the same name

is there a way that i can differentiate the value with the same name?

<input type="hidden" name="id" value="name1">
<input type="hidden" name="id" value="name2">
<input type="hidden" name="id" value="name3">

is there a way that when i post an id, the value that will be posted would be name2?

Upvotes: 0

Views: 62

Answers (3)

Bhumi Shah
Bhumi Shah

Reputation: 9476

Use array for the name

<input type="hidden" name="id[]" value="name1">
<input type="hidden" name="id[]" value="name2">
<input type="hidden" name="id[]" value="name3">

which provides all the values in array.

hope this help.

Upvotes: 2

sockeqwe
sockeqwe

Reputation: 15919

No, you can not do that. You need to specify different names or to use somthing like an array. This can be done by setting the name id[].

What want you to do?

You can set the value of the hidden field dynamicaly with javascript, if that is what you are looking for.

Upvotes: 0

Roy
Roy

Reputation: 987

use different names for different variables.

<input type="hidden" name="id2" value="name2">

Upvotes: 0

Related Questions