RJS to change image on submit button

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...

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

You 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

Frederick Cheung wrote:

or even page['submit_button'].src= 'someother_picture.gif' (which will
result in the same output).

Fred

Thanks Fred. Sometimes things are blindingly obvious :slight_smile: I've used your
suggestion and it's made for cheaner code. Many Thanks.