Need to set default value of radio group when not checked

forms, html, javascript, post

Solution

You can do something like this:

<form action="receive.php" method="post">
    <input type="radio" name="rad" value="one" /> One <br />
    <input type="radio" name="rad" value="two" /> Two <br />
    <input type="radio" name="rad" value="three" /> Three <br />
    <input type="hidden" name="rad" value="null" />
    <input type="submit" value="submit" />
</form>

Now if you haven't checked any radio button, you will get "null" input value, but remember `"null"` is not same as `NULL` in PHP.

Problem

In my html form, I have a group of radio buttons ``` <form action="receive.php" method="post"> <input type="radio" name="rad" value="one" /> One <br /> <input type="radio" name="rad" value="two" /> Two <br /> <input type="radio" name="rad" value="three" /> Three <br /> <input type="submit" value="submit" /> </form> ``` I have a scenario where no radio button is checked. In such case, my server-side php receives input value as `false`. What I want to do is change false to `null` or `undefined`. Is that possible? Any help is greatly appreciated.

Original source