jquery radio buttons

10 views
Skip to first unread message

fugee ohu

unread,
Apr 2, 2017, 1:24:13 AM4/2/17
to Ruby on Rails: Talk
Can I treat radio buttons the same as other fields in my form for the purposes of jquery script
Can I use 
$("#example").change(function(e) 
  if (e.target.value=='Yes') 
  ...

Or do I have to use a different method?

Robby O'Connor

unread,
Apr 2, 2017, 6:25:52 AM4/2/17
to rubyonra...@googlegroups.com, fugee ohu
http://api.jquery.com/checkbox-selector/
> --
> You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to rubyonrails-ta...@googlegroups.com
> <mailto:rubyonrails-ta...@googlegroups.com>.
> To post to this group, send email to rubyonra...@googlegroups.com
> <mailto:rubyonra...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/0b70c901-972e-499b-8921-ac9e1e5ced54%40googlegroups.com
> <https://groups.google.com/d/msgid/rubyonrails-talk/0b70c901-972e-499b-8921-ac9e1e5ced54%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Robby O'Connor

unread,
Apr 2, 2017, 6:27:03 AM4/2/17
to rubyonra...@googlegroups.com, fugee ohu
Looks like this answers your question: http://stackoverflow.com/a/7031408

fugee ohu

unread,
Apr 2, 2017, 9:24:47 AM4/2/17
to Ruby on Rails: Talk, fuge...@gmail.com


On Sunday, April 2, 2017 at 6:27:03 AM UTC-4, Robert O'Connor wrote:
Looks like this answers your question: http://stackoverflow.com/a/7031408

On 04/02/2017 06:25 AM, Robby O'Connor wrote:
> http://api.jquery.com/checkbox-selector/
>
> On 04/02/2017 01:24 AM, fugee ohu wrote:
>> Can I treat radio buttons the same as other fields in my form for the
>> purposes of jquery script
>> Can I use
>> $("#example").change(function(e)
>>   if (e.target.value=='Yes')
>>   ...
>>
>> Or do I have to use a different method?
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to rubyonrails-ta...@googlegroups.com

  This isn't the place to post links to other forums Answer the question or don't 
 

Colin Law

unread,
Apr 2, 2017, 9:49:21 AM4/2/17
to Ruby on Rails: Talk
On 2 April 2017 at 14:24, fugee ohu <fuge...@gmail.com> wrote:

  This isn't the place to post links to other forums Answer the question or don't 

You would be more likely to get helpful answers if you ever said thanks when people here do help you.
For example your post with subject "conditional validatiobs" (whatever that means) on 29th March.

Colin

James Jelinek

unread,
Apr 2, 2017, 10:26:10 AM4/2/17
to rubyonra...@googlegroups.com
Agreed. Politeness and kindness goes a long way. 

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtvmcJg6woroJQ3h64zMOYUc_2pnUcnyZoEfY2Yr_z11A%40mail.gmail.com.

fugee ohu

unread,
Apr 2, 2017, 10:55:16 AM4/2/17
to Ruby on Rails: Talk
Then thanks and sorry and sorry to James too I didn't mean  to be unpolite or ungracious although we need our forum we can't just link to answers on others 
To answer my own question A: Yes; The reason it didn't work is because rails actionview radio button helper creates radio buttons which successfully relay info on form submission but actually the html it renders leaves out a foward slash for the closing greater than sign > should be /> so it causes jquery not to pick it up properly; maybe, that's how i fixed it i think

fugee ohu

unread,
Apr 2, 2017, 10:58:21 AM4/2/17
to Ruby on Rails: Talk


On Sunday, April 2, 2017 at 9:49:21 AM UTC-4, Colin Law wrote:
I do delete my invalid unanswered questions although there's a lag

Colin Law

unread,
Apr 2, 2017, 11:06:45 AM4/2/17
to Ruby on Rails: Talk
No you don't, they still appear in my inbox. It is impossible for you to deleted them from there.
Also there is no reason not to reply by pointing to an answer that already exists out on the web. Whether it is in a reply on another support group or on a web page somewhere or a reference to some docs. Do you suggest that we copy and paste the answer here, so filling the web up with duplicate data?  It is a lot easier for you to click on a link than it is for someone else to copy/paste a reply from elsewhere. You should be grateful that he/she took the time to look it up for you.

Colin
 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b93f892d-3ccc-4f4d-b12c-829e29e52217%40googlegroups.com.

Walter Lee Davis

unread,
Apr 2, 2017, 11:12:59 AM4/2/17
to rubyonra...@googlegroups.com

> On Apr 2, 2017, at 10:55 AM, fugee ohu <fuge...@gmail.com> wrote:
>
> The reason it didn't work is because rails actionview radio button helper creates radio buttons which successfully relay info on form submission but actually the html it renders leaves out a foward slash for the closing greater than sign > should be /> so it causes jquery not to pick it up properly; maybe, that's how i fixed it i think


Rails since v3 has used HTML5 for its templating language by default. If you haven't changed anything, that's the expectation. HTML5 allows but does not require the "self-closed" tags of XHTML -- <hr /> and <hr> are equivalent, IOW.

In my (admittedly limited) experience with jQuery (I have far more experience with Prototype), I doubt very much that the trailing slash had anything to do with the matcher. Both Prototype and jQuery use the Sizzle matcher, and it's extremely good. More likely, you may have inadvertently written invalid HTML (regardless of level) including multiple items with the same ID attribute. It's always a good first step when diagnosing JavaScript weirdness to view source in a browser, copy it, and paste it into https://validator.w3.org to see if there are any obvious errors. jQuery won't complain if you use the same ID twice (or more) in a page, but it will do unpredictable things when you try to access an attribute or value.

Finally, the Rails checkbox / radio button helper provides an empty same-name hidden variable for each item that needs one, since in all HTML/CGI interfaces, the lack of a checkbox does not send a foo=false in a form post, it just does not send foo at all. Thus you will see this construction in your radio buttons:

<input type="hidden" name="foo" value="" />
<input type="radio" name="foo" value="bar" />
<input type="radio" name="foo" value="baz" />

This means that the foo key will be present in all of your submissions, regardless if any of the options are checked or not. This is of much more importance in checkboxes than radio buttons, since without it, there would be no way to "un-check" a checkbox using an HTML form.

Walter
Reply all
Reply to author
Forward
0 new messages