Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing hidden input fields in HTML Select option

Does anyone know if it's possible to pass a hidden request parameter in with a <select> <option> element in a HTML form?

So for example, if the user selected <option value="foo">foo</option> from a <select> list of options, could I somehow pass a hidden value in, as well as the "foo" value, and retrieve that as a request parameter? E.g. <input type="hidden" name="x" value="bar"/> would enable me to get the values "foo" and "bar" from the request when the user selected the foo option.

Thanks

like image 655
Andy Birchall Avatar asked Jul 23 '09 08:07

Andy Birchall


People also ask

How do you make a select field hidden in HTML?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <select> element is not visible, but it maintains its position on the page.

How do I hide hidden fields in inspect element?

It is not possible to hide elements from the DOM inspector, that would defeat the purpose of having that tool. Disabling javascript is all it would take to bypass right click protection. What you should do is implement a proper autologin.


1 Answers

If you need to use a hidden field for each options of the select dropdown, you can set that value in your own attribute in tag, instead of setting it into hidden field.

<option value="foo" fooData="foo|bar">foo</option>
<option value="foo2" fooData="foo2|bar2">foo2</option>

like image 200
Foram Shah Avatar answered Sep 18 '22 18:09

Foram Shah