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,

On Wed, 2010-01-20 at 22:44 +0100, Frank K. wrote:

“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?

I think you made a copy / paste mistake. I can’t find a character’s
worth of difference between the two. Try again, or point me.

Best regards,
Bill

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:

Hi Frank,

On Wed, 2010-01-20 at 22:44 +0100, Frank K. wrote:

“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?

I think you made a copy / paste mistake. I can’t find a character’s
worth of difference between the two. Try again, or point me.

Best regards,
Bill

On Jan 20, 10:08Â pm, Frank K. [email protected] wrote:

I will give that a try.

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

Fred

I will give that a try.

Thank you guys.

Steve K. wrote:

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs