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

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:

ok thanks it works for me :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.