php - radio buttons post show value even none of the buttons are checked how to validate this? -


i have registration form wich has gender radio option showing male or female. in html none checked because want user check one. this:

<label class="radio">     <input type="radio" name="gender" id="optionsradios1" value="female">female </label> <label class="radio">     <input type="radio" name="gender" id="optionsradios2" value="male">male </label> 

i submit data trough jquery ajax. strange thing post of al inputs shows

[gender] => male if submit form none of 2 options checked

so how can validate if never posts empty?

*i want return error if no option selected forces user select right gender..

one quick way of doing defaulting choice in ui. makes sure value non-empty because can't "uncheck" radio button.

<input type="radio" name="gender" id="optionsradios1" value="female" checked> female 

edit:
write own submit function, , bind submit button's onclick()

function submit() {   if (!$("#optionsradios1").prop("checked") && !$("#optionsradios2").prop("checked")) {     alert("please select gender");   }   else {     //whatever submit   } } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -