disable submit_tag after click

This code disables the 'Save' button once clicked, but doesn't seem to send the form data. <%= submit_tag 'Save', :class => 'submit', :onclick => "document.getElementById('save_button').disabled=true;", :id => "save_button" %>

This code sends the form data and a record is created, but isn't disabled once clicked. A user can click this many times, creating a new record each time. <%= submit_tag 'Save', :class => 'submit', :onclick => "document.getElementById('save_button').disabled=true;", :id => "save_button" %>

Anyone know of a way to fix the javascript to disable the 'Save' button and also send the form data when clicked once?

Thanks,

Frank

Hi Frank,

When you write that onclick, don't you have to also make it submit the form? Try this:

<%= submit_tag 'Save', :class => 'submit', :onclick => "document.getElementById('save_button').disabled=true;document.forms["myform"].submit();", :id => "save_button" %>

changing the id, obviously.

Sorry about that. I meant to replace ":onclick" with ":onchange".

bill walton wrote:

I will give that a try.

Thank you guys.

Steve Klabnik wrote:

I will give that a try.

Also look at submit_tag's :disable_with option - no need to reinvent the wheel!

Fred