Saranya Sadhasivam
Saranya Sadhasivam

Reputation: 1294

What will happen if I use the same name for submit button which I used for form elements as an array in PHP?

I have used name="question[]" for multiple select box and the same name used for submit button name as name="question[]"

How can I get the values of the select box without the submit button?

Upvotes: 0

Views: 98

Answers (4)

rcambrj
rcambrj

Reputation: 602

If you can use a jQuery/Sizzle variant on the front

$('select[name="question[]"]').val();

Will return the selected value from the select box by that name. You can then populate some other field with that value before submitting to the server.

Upvotes: 0

Manigandan Arjunan
Manigandan Arjunan

Reputation: 2265

You can get both the elements value as follows,

You can then access it using the following:

$_POST['question'][0]; 
$_POST['question'][1];

You can get the values of select box and submit button now.

Upvotes: 0

Barmar
Barmar

Reputation: 781726

The best solution is to fix the name clash.

If the value of the submit button can never be one of the select values, you can ignore any element of $_POST['question'] that has that value.

Upvotes: 0

Nathan Payne
Nathan Payne

Reputation: 83

Change the name of your submit button... it shouldn't be the same.

Upvotes: 1

Related Questions