Open In App

How to specify the value to be sent to a server ?

Last Updated : 06 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to specify the value of an option so that this value is sent to the server.

The value attribute can be used for this purpose. It specifies the value to be sent to a server in the <option> element. The content between the opening and closing tags of <option> will be displayed by the browser in the drop-down list. However, the value that was defined in the value attribute is what will be sent to the server when the form is submitted.

Syntax:

<option value="value">

Example: In this example, we will set the value which is sent to the server.

HTML




<html>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <h3>
        Select an option to see its
        value being sent to the server
    </h3>
    <form action="form.php">
        <label for="Subject">
            Subject:
        </label>
        <select id="subject" name="subject">
            <option value="phy">
                PHYSICS
            </option>
            <option value="chem">
                CHEMISTRY
            </option>
            <option value="bio">
                BIOLOGY
            </option>
            <option value="math">
                MATHEMATICS
            </option>
        </select>
        <input type="submit" value="Submit">
    </form>
</body>
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads