0

i have a html form to develope. but form is not getting submitted until i don't press Submit button. i want, when we select any radio button or checkbox and press Enter it should be submitted

my html is like:

<html>
 <head>
 <title>select preferences</title>
 </head>
 <body>
 <input type="radio" name="sex" value="male" /> Male<br/>
 <input type="radio" name="sex" value="female" /> Female<br/>
 <button type="submit">Click Me!</button> 
 </body> 
</html>

please help me resolve this. and give some links for related tutorial.

duedl0r
9,4343 gold badges34 silver badges46 bronze badges
asked Nov 22, 2011 at 7:36
1
  • you should define a default button for that : Commented Nov 22, 2011 at 7:38

3 Answers 3

4

You're missing the <form> tag.

Have a look here.

answered Nov 22, 2011 at 7:37
Sign up to request clarification or add additional context in comments.

Comments

0

On change of your radio buttons, submit the form using:

$('#form-id').submit();

So, your HTML should be:

<form id='form-id' method='post' action=''>
<input type="radio" name="sex" value="male" /> Male<br/>
<input type="radio" name="sex" value="female" /> Female<br/>
<button type="submit">Click Me!</button> 
</form>

and your script should be:

$(function(){
 $('input[type=radio]').change(function(){
 $('#form-id').submit();
 });
});
answered Nov 22, 2011 at 7:38

Comments

0

Add form tag

<form method="post" action="somepage">
//add you inputs here
<form>
answered Nov 22, 2011 at 7:38

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.