验证单选按钮标记

时间:2012-01-23 19:40:55

标签: javascript ruby-on-rails

我的rails项目中有一个radio_button_tag,我想在没有选择选项的情况下进行验证。

<% @votes.each do |vote| %>

  <%= radio_button_tag "escolha", "#{vote.id}" %>

<% end %>

我可以这样做吗?

1 个答案:

答案 0 :(得分:0)

function Form1_Validator(theForm)
{
// require at least one radio button be selected
var radioSelected = false;
for (i = 0;  i < theForm.votes.length;  i++)
  {
if (theForm.votes[i].checked)
radioSelected = true;
  }
if (!radioSelected)
  {
alert("Please select one of the \"Vote\" options.");
return (false);
  }
}

对于javascript,您可以使用上述内容。对于Rails,您可以在另一个问题中看到我的答案。