Hi I have an observer that fires on the basis of a drop-down. I need to change the icon on the submit button of a form based on this value. I created the submit button using "image_submit_tag". I have it working with this code in my RJS template: if params[:type] == "type_a" page.replace_html "submit_button", ''<input class="submit" src="/images/btn_type_a.gif" type="image" />'' else page.replace_html "submit_button", ''<input class="submit" src="/images/btn_type_b.gif" type="image" />'' end I expect there is a better way to do this than having to replace the code generated by my image_submit_tag. I would rather just replace the image directly. Any help/ideas appreciated... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 23 Mar 2008, at 13:35, John Lane wrote:> > > Hi I have an observer that fires on the basis of a drop-down. > > I need to change the icon on the submit button of a form based on this > value. I created the submit button using "image_submit_tag". > > I have it working with this code in my RJS template: > > if params[:type] == "type_a" > page.replace_html "submit_button", > ''<input class="submit" src="/images/btn_type_a.gif" type="image" / > >'' > else > page.replace_html "submit_button", > ''<input class="submit" src="/images/btn_type_b.gif" type="image" > />'' > endYou could always just do page << "$ (''submit_button'').src=''someother_picture.gif''"; or even page[''submit_button''].src= ''someother_picture.gif'' (which will result in the same output). Fred> > > I expect there is a better way to do this than having to replace the > code generated by my image_submit_tag. I would rather just replace the > image directly. > > Any help/ideas appreciated... > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Lane wrote:> if params[:type] == "type_a" > page.replace_html "submit_button", > ''<input class="submit" src="/images/btn_type_a.gif" type="image" />'' > else > page.replace_html "submit_button", > ''<input class="submit" src="/images/btn_type_b.gif" type="image" > />'' > end > > I expect there is a better way to do this than having to replace the > code generated by my image_submit_tag. I would rather just replace the > image directly.The following springs to mind: page << "$$(''input.submit'')[0].src = ''/images/btn_#{params[:type]}.gif''" Assuming that params[:type} always maps into the image name. Untested, but I''ve done similar things before... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> or even page[''submit_button''].src= ''someother_picture.gif'' (which will > result in the same output). > > FredThanks Fred. Sometimes things are blindingly obvious :) I''ve used your suggestion and it''s made for cheaner code. Many Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---