开发者

MVC Form just doesn't post if no radiobutton selected

I have a user registration form, with one set of radio buttons for the user's selected package. The form first renders with none of the radio buttons selected, as I want it to. However, if I don't select any option, the form merely doesn't post, based on some client side validation, yet there is no开发者_开发知识库 indication of what is wrong. To me it's obvious, but to my users it definitely won't be. How can I inform the user what is wrong?

The radio buttons are in a table, not a RadioButtonList, as I wanted a few columns per button, so there is no single control I can attach a validation message to.


On the form:

<form name="myForm" onsubmit="validate(this)" action="http://somewhere.there" >

And a simple validation:

<script type="text/javascript">
 validate(form){
   if(!form.package[0].checked & !form.package[1].checked){
       alert("select something please");
       return false;
   }
</script>

Assuming that you check box are named 'package' and there are only two options. The return false will stop the form being submitted if no checkboxes are selected.

There are of course more elegant ways of doing this, but this will work:-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜