Change Params with Rails after Checkbox is checked -


i have page display media has been uploaded website. there 3 check boxes, 1 each type of media, check boxes images, catalog_images, , videos. once 1 checked want page reload same page add check box parameters being checked, display media(s) checked.

i'v been attempting javascript unsuccessfully. hoping rails have built in function or me out. continue doing research , update question if doesn't beat me it.

edit: had request code, didnt want include because in production , has lot of junk around i'll try clean , give , idea of im doing

<div class="panel">     <h3>create media</h3>     <div>         image: <%= check_box_tag 'catalog image', :catalog_images %> | images: <%= check_box_tag 'images', :images %> | video: <%= check_box_tag 'videos', :videos %>         <br />         <% if @filenames %>             <table class='list'>                     <th>lots</th>                     <th>sub lot creation</th>            <% if :videos %>               <% @videos.reject(&:blank?).uniq.each |filename| %>                     <% basename = file.basename(filename, '.*') %>                      <tr>                         <td><%= basename %></td>                         <td><%= text_field_tag :low_range %> <%= text_field_tag :high_range %></td>                     </tr>              <% end %>           <% end %>    </table>         <% end %>         <%= link_to "create image", mass_create_from_media_admin_event_lots_path(@event, :images => true) %>     </div> </div> 

so when each checkbox tagged want reload , have :videos, :catalog_images, :images true if checked. know validation isn't complete each media, @ home tried create representation of want

if understand correctly want reload page , append ?videos=checked url?

if that's case can (i suppose you're using jquery, shouldn't have problems rewriting coffee script):

$('input:checkbox').change(function () {     var currenturl = window.location.href;     // media type     var mediatype = $(this).val();     // set true if checkbox has been checked, false otherwise     var ischecked = ($(this).attr('checked')) == 'checked' ? true : false;      if (ischecked == true) {         // in case have other params in url         if (currenturl.indexof('?') !== -1){            currenturl += '&' + mediatype ' + '=true';         } else{            currenturl += '?' + mediatype ' + '=true';         }     }      window.location.href = currenturl; }); 

i didn't run code , need solve other use cases (e.g. should happen when user unchecks checkbox?)

anyway solution kind of messy. suggest use either normal form submit button or asynchronous call , change parts of page need to.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -