Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with disable code

Status
Not open for further replies.

IncaWarrior

Programmer
Joined
Jul 25, 2003
Messages
5
Location
US
I am trying to make a form that will disable after it has been clicked (So people don't submit more than once). I found this code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin
function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements;
if (tempobj.type.toLowerCase() == &quot;submit&quot;)
tempobj.disabled = true;
}
}
}
// End -->

(I think that's all i need from it)
in the head and:

<form method=post action=&quot;[form_action]&quot; onSubmit=&quot;return disableForm(this);&quot;>

and the form (<input type=submit name=submit value=&quot;Submit&quot;> ).

the button becomes disabled after clicking on it, but it is not submitted, anyone know how to do this?
 
No reason to disable the whole thing, is there?

Code:
<input type=&quot;submit&quot; id=&quot;Submitty&quot; name=&quot;Submitty&quot; value=&quot;Send the data!&quot; onclick=&quot;document.FormName.Submitty.disabled='disabled';return true;&quot;

If the submit button is disabled, then they can't submit unless they hit the [ENTER] button, and if you, on Submitty's onclick event, drive the focus to an element in another form, then even hitting [ENTER] won't execute the critical form.

Thanks for giving me an opportunity to think about a legit way to avoid double-hitting the [SUBMIT] button.

Hope that helps.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Hey Ed,

I can only see two things that I would change in your &quot;onclick&quot; event. Like this:
Code:
<FORM name=&quot;myform&quot; action=&quot;myAction&quot; method=&quot;POST&quot; onsubmit=&quot;this.Submitty.disabled=true;return true;&quot;>

<input type=&quot;submit&quot; id=&quot;Submitty&quot; name=&quot;Submitty&quot; value=&quot;Send the data!&quot; onclick=&quot;this.disabled=true;return true;&quot;>

This should handle the user hitting ENTER in the form to cause a resubmit. Another thing that could be done would be change the FORM's action attribute to be null. That way subsequent submits would not do anything.

Cheers


Einstein47
(&quot;Vision without action is a daydream - Action without vision is a nightmare. Japanese Proverb&quot;)
 
This should stop subsequent submits:

<form action=&quot;...&quot; onsubmit=&quot;return window.x?false:window.x=1&quot;>

Adam
 
the problem is that it does the form action but doesn't actually submit the data so when the submit button is pressed, it becomes disabled then does the form action. It isn't important that enter not work since the last input is a textfield and i'm not too worried about people pressing tab. How can I get it to actually submit and do the action?
 
<input type=submit name=Submit value=&quot;Submit&quot; onClick=&quot;form.Submit.disabled=true; form.submit();&quot;>

where form is the name of the form. as i said, the form disables and does the form action, but doesn't submit the information
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top