# Verifying if radio buttons are checked

**URL:** <https://www.ruby-forum.com/t/verifying-if-radio-buttons-are-checked/121059>\
**Category:** Rails\
**Created:** [November 23, 2007, 10:59am UTC](https://www.ruby-forum.com/t/verifying-if-radio-buttons-are-checked/121059 "2007-11-23T10:59:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [November 23, 2007, 10:59am UTC](https://www.ruby-forum.com/t/verifying-if-radio-buttons-are-checked/121059/1 "2007-11-23T10:59:17Z")

</div>

Hello,  
I’ve 4 radio\_buttons dynamically generated :  
Code :  
\<% @collection.each do |q| %\>

\<%= q.value %\>

  
\<%= radio\_button q.id.to\_s, “choice”, “1” %\>  
q.choice1  
\<%#, :onclick =\> remote\_function(:url =\> {:action =\> …%\>  
q.choice2  
\<%= radio\_button q.id.to\_s, “choice”, “2”%\>  
\<%end%\>

Everytime the user click on a radio\_button, I wan’t to verify that all  
others are checked and show a link to the next page. But I can’t verify  
if all my radio\_buttons are checked. I can only show the link if only  
one radio is clicked.  
Code :

[…],:onclick =\> remote\_function(:url =\> {:action =\> “next”}) %\>  
…

in the controller  
Code :

def next  
render :update do |page|  
page.replace\_html “next”,link\_to(“Next”,:action =\>“next\_page”)  
end  
end

thanks

---

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [November 23, 2007, 11:37am UTC](https://www.ruby-forum.com/t/verifying-if-radio-buttons-are-checked/121059/2 "2007-11-23T11:37:07Z")

</div>

you could put them all in a remote form and instead of calling the  
remote\_function in onclick submit that form. than you get them all in  
your controller as params.

---

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [November 23, 2007, 11:47am UTC](https://www.ruby-forum.com/t/verifying-if-radio-buttons-are-checked/121059/3 "2007-11-23T11:47:38Z")

</div>

Thorsten M. wrote:

> you could put them all in a remote form and instead of calling the  
> remote\_function in onclick submit that form. than you get them all in  
> your controller as params.

Can you give me more details plz (a little example of code…)  
Thanks

---

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [November 23, 2007, 12:03pm UTC](https://www.ruby-forum.com/t/verifying-if-radio-buttons-are-checked/121059/4 "2007-11-23T12:03:45Z")

</div>

\<%= form\_remote\_for(…) do |f| %\>

you checkboxes go here like that:  
\<%= f.check\_box “col\_name\_or\_whatever”, :onchange =\>  
“$(‘your\_form\_id’).submit();” %\>

\<% end %\>

in you controller you get all the form data as with any other form. make  
sure, every checkbox get’s it’s own name/id

---

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [November 23, 2007, 2:07pm UTC](https://www.ruby-forum.com/t/verifying-if-radio-buttons-are-checked/121059/5 "2007-11-23T14:07:04Z")

</div>

Thorsten M. wrote:

> \<%= form\_remote\_for(…) do |f| %\>
> 
> you checkboxes go here like that:  
> \<%= f.check\_box “col\_name\_or\_whatever”, :onchange =\>  
> “$(‘your\_form\_id’).submit();” %\>
> 
> \<% end %\>
> 
> in you controller you get all the form data as with any other form. make  
> sure, every checkbox get’s it’s own name/id

I’ve written this code  
\<% remote\_form\_for :check\_boxes, “check\_boxes”, :url =\> { :action =\>  
“validate”}, :html =\> { :id =\> “check\_boxes” } do |f| %\>

\<%= radio\_button q.id.to\_s, "choice", "1", :onclick =\> "$('check\_boxes').submit();", :current\_page =\> @pager.current\_page%\>

but when I click on the radio\_button, I’ve the next error :  
try {  
Element.update(“next”, “\u003Ca  
href="/questionnaires/list\_questions?page=1"\u003ENext\u003C/a\u003E”);  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
alert(‘Element.update("next", "\u003Ca  
href=\"\/questionnaires\/list\_questions?page=1\"\u003ENext\u003C\/a\u003E");’);  
throw e }

What does it mean?

---

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [November 23, 2007, 2:29pm UTC](https://www.ruby-forum.com/t/verifying-if-radio-buttons-are-checked/121059/6 "2007-11-23T14:29:04Z")

</div>

your response:

page.replace\_html “next”,link\_to(“Next”,:action =\>“next\_page”)

seems to generate an error (so at least clicking the checkbox seems to  
submit the form and call the action)  
as far as i can see, it tries to render the ajax response as normal html  
or text

(was this rendered as content of the page or an actual error message by  
the browser?)
