0

hi i have a select(dropdown button) which displays various chioce for the user to select .. i want to validate it that if the user does not select any choice i should not able to do any action how to do. Is there any like required available for text box in html

2
Contributors
2
Replies
20
Views
3 Years
Discussion Span
Last Post by hiiiiii@
1

Hi,

You can use the required attribute:

<form method="post" action="">

    <label for="fruits">Choose an option:</label>

    <select name="fruits" required>

        <option value="">------</option>
        <option value="fujiapple">Apple</option>
        <option value="vanillaorange">Orange</option>
        <option value="pandoracherry">Cherries</option>

    </select>

    <input type="submit" name="submit" value="submit" />
</form>

By adding an empty option the form will not be submitted. You could also add a javascript check, but you will always need a server-side validation: you cannot trust what is sent by the client.

Related post:

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.