[fixed] Pass or Send Value From select option HTML – Valid

In HTML how to send or How to pass data from <select> <option>.

It’s easy to send data from select option to the laravel and PHP or anywhere.

This post explains how to send data from a select option in PHP, Laravel and whatever. To do this, you need to add a name attribute to your select element. Make sure you also add a value attribute to each option in the select element to specify the value that will be sent when the option is selected.

It’s important to note that you can’t have two select elements with the same name attribute. If you want to add more select elements, you need to give them different names.

Here’s an example code snippet:

How to Send Select Option Value HTML

<select name="users">
  <option value="tom">TOM</option>
  <option value="JOY">Joy</option>
  <option value="Elon Musk">Elon Musk</option> 
</select>

If you adding

<select >
<option></option>

</select>

and not send data not send then you are forgeting the named it

juat add name on the select

<select name=”example_name” id=”defaultSelect” class=”form-select”>

<select name="url">
  <option></option>
</select>

Important for adding Select Option for send data

don’t forget the add value on the option

See example.

<option value=”example value”>example value </option>

value=”example value” for sending php or laravel and inside >example value< for displaying while select

so while select the displaying item what will be select that defined on value attribute

Final code

<select name="users">
  <option value="tom">TOM</option>
  <option value="JOY">Joy</option>
  <option value="Elon Musk">Elon Must Bro</option> 
</select>

Note.

Displayed Elon Must Bro for select, but data will send only Elon Musk, not Bro added because value is set Elon Musk

Another Important Note

you don’t have two select html code with same named like users and users, which will be in the last that will responable not first one.

I mean if you have 2 select HRML code

like

<select name=”users”> <option value=”tom”>TOM</option> <option value=”JOY”>Joy</option> <option value=”Elon Musk”>Elon Must Bro</option> </select>

and

<select name=”users”> <option value=”tom”>TOM</option> <option value=”JOY”>Joy</option> <option value=”Elon Musk”>Elon Must Bro</option> </select>

both are same

and It will send data from last one not from first one

so

If you want add more select then you need to change the name of select

example

<select name="users">   
    <option value="tom">TOM</option>   
    <option value="JOY">Joy</option>   
    <option value="Elon Musk">Elon Must Bro</option>  
</select>

<select name="younger_people">
   <option value="tom">TOM</option>
   <option value="JOY">Joy</option>
   <option value="Elon Musk">Elon Must Bro</option>
</select>

Data will send usert and younger_people for same value you can change anything,

just changing attribute name it’s seperaed two type.

Thanks.

Leave a Reply