Search code examples
htmlformsvalidationradio-button

Radio Button Validation HTML FORM


I have this form:

<form name="form" action="order.php" method="post">
Please select Amount:<br />
<input type="radio" name="amount" value="25" id="25" /> <label for="25">$25</label><br />
<input type="radio" name="amount" value="50" id="50" /> <label for="50">$50</label><br />
<input type="radio" name="amount" value="75" id="75" /> <label for="75">$75</label><br />
<input type="radio" name="amount" value="100" id="100" /> <label for="100">$100</label><br />
<input type="radio" name="amount" value="200" id="200" /> <label for="200">$200</label><br />
<input type="submit" value="Submit">
</form>

I am wondering how I can do validate to make sure that one of these Radio Button's are selected?

I have tried a few different things, I have looked on Google and visited almost every site on the first and second pages and could not get it working..

Thanks,
Chad.


Solution

  • One solution without using client-side scripting would be to select one by default using CHECKED:

    <input type="radio" name="amount" value="25" id="25" CHECKED /> 
    

    Here is a fiddle to show you.

    If this won't work for your situation, look into using jQuery or Javascript to implement a solution.

    This should help get you started: How can I check whether a radio button is selected with JavaScript?

    Good luck.