Hi all experts, Hi Have a form, <form action="" method="post"> <input type="radio" name="sex" value="male">Male <input type="radio" name="sex" value="female">Female<br /> <input type="radio" name="age" value="1">10-17 <input type="radio" name="age" value="2">18-30<br /> </form> HTML: Now what i want to do, when a user select sex and age both, then javascript submit form automatically and dynamically, and get response from a php file where submit information, please help me
Hi. There're already a lot of similar discussions somewhere inside Digital Point, have you search? I'd do it to something roughly like this: <!DOCTYPE html> <html> <head> <script> function mySubmitHandler(myForm){ var sets = myForm.getElementsByTagName('fieldset'), readySetsCount = 0; for (var i = 0; i < sets.length; i++){ var fields = sets[i].getElementsByTagName('input'); for (var j = 0; j < fields.length; j++){ if (fields[j].checked){ readySetsCount++; break; } } } if (readySetsCount < 2){ alert('form is not ready'); return false; } else return true; } </script> </head> <body> <form action="" method="post" onsubmit="return mySubmitHandler(this)"> <fieldset> <label> <input type="radio" name="sex" value="male"> <span>Male</span> </label> <label> <input type="radio" name="sex" value="female"> <span>Female</span> </fieldset> <fieldset> <label> <input type="radio" name="age" value="1"> <span>10-17</span> </label> <label> <input type="radio" name="age" value="2"> <span>18-30</span> </label> </fieldset> <input type="submit"> </form> </body> </html> HTML:
No Dude, I Don't want to add submit button, as I mention, It submit auto when select sex and age will be select, and don't want to refresh the page
Check out this you need to add jquery plugin and code like: <form action="" method="post" id="jit"> <input type="radio" class="sex" name="sex" value="male">Male <input type="radio" class="sex" name="sex" value="female">Female<br /> <input type="radio" class="age" name="age" value="1">10-17 <input type="radio" class="age" name="age" value="2">18-30<br /> </form> HTML: $( ".sex" ).on( "click", function() { if($( ".age:checked" ).length==1){ $("#jit").submit(); } }); $( ".age" ).on( "click", function() { if($( ".sex:checked" ).length==1){ $("#jit").submit(); } }); Code (JavaScript):
Uhm, no. If he doesn't want to refresh the page, he needs to use some sort of AJAX-call - and display the result. Something like this: $("input[name=sex],input[name=age]").change(function() { if ($("input[name=sex]").val() != '' && $("input[name=age]").val() != '') { $.post('processform.php', serialize($('#formID')), function(data) { alert(data); // returnvalue from processform.php }); } } Code (markup): Something like that - not tested, might need some tweaking
Is there some reason you really seem to want to piss all over accessibility and usability with scripttardery to avoid having a simple submit button? See, this is EXACTLY the type of "Gee ain't it neat" bullshit I usually am ranting and raving about what total nonsense it is. JS for nothing and your scripts for free, that ain't working, that's not how you do it... Of course it's then hardly a shock the drooling mouth-breathing jQuery re-re's and their idiotic bloated halfwit code bloat come pouring out of the woodwork...