Javatpoint Logo
Javatpoint Logo

How to get selected option value in PHP

In this article, we will learn how to get selected option values in PHP. In this, we will learn some basic PHP concepts, and after that, we learn this concept with the help of various examples.

What do you mean by PHP?

PHP is a widely used, open-source server-side scripting language that allows web developers to quickly create dynamic and interactive web pages. PHP files have extensions with .php. PHP is compatible with almost all types of web servers on almost every operating system free of cost.

How to get selected option value in PHP

What do you mean by option value in PHP?

The <select> and <option tags> are used to create drop-down menus. They allow the user to select single or multiple choices from a list of options in PHP.

Syntax:

The various attributes used with the <select> tag are:

  • Multiple: It is used to select the multiple options in the list.
  • Name: It is used to specify a name for the drop-down list.

The various attributes used with <option> tag are:

  • Value: It is used to specify the value that is sent when the form is submitted.
  • Selected: It is used to specify the preselected choice when the form is initially loaded in a browser.

Let's take various examples of how to get selected option values in PHP.

Example 1:

Write a Program on how to get selected option value in PHP.

Explanation:

In the above example, we have created an option value list with the help of <select> and <option> tag. In this, we have selected an option value from the option value list, and after selecting the option, we click on a button then the following message is displayed with the selected option.

If you have not selected the option value, the following message is displayed.

Output:

The following figure shows the output of this example:

How to get selected option value in PHP

Example 2:

Write a Program on how to get selected multiple option values from a drop-down list in PHP.

Explanation:

In the above example, we have created an option value list with the help of <select> and <option> tag. In this, we have the option of selecting more than one value from the options list using the "multiple option." After selecting the option, we click on a button then the following message is displayed with the selected option.

If you have not selected the option value, the following message is displayed.

Output:

The following figure shows the output of this example:

How to get selected option value in PHP





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA