简体   繁体   中英

Ruby on Rails: Jquery/ajax dynamic form fields

I'm in the process of implementing dynamic form fields. So far, I have some jQuery that does the trick, however I have to manually refresh the page to see the change.

How can I make this dynamic? I'm under the impression I'll need to include ajax somewhere, but I'm having issues finding good resources.

Here is the code I'm using;

jQuery ->
    $(
        if ($('#subject_enrolled').val() == '0')
            $('#subject_reason_not_enrolled').show()
        else
            $('#subject_reason_not_enrolled').hide();
    );

Any help/resources would be greatly appreciated.

I'm assuming #subject_enrolled is a checkbox. You just need to listen for the change events on that checkbox and then update the display of your #subject_reason_not_enrolled . This is covered quite a bit in other posts. Here's one: How to listen to when a checkbox is checked in Jquery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM