Forum Moderators: open

Message Too Old, No Replies

Disabling Button after Form Submit

IE seems to remove onclick changes after form submit

         

chadmg

5:29 pm on Jun 2, 2004 (gmt 0)

10+ Year Member



this does not seem to work in IE 6...

<form name="form1" method="post" action="?">
<input name="cont" value="Submit" type="button" onclick="document.form1.cont.value='Please wait...';document.form1.cont.disabled = true; document.form1.submit();">
</form>

It works when you remove the submit. But after the form is submitted the onclick effects magically disappear. :( Any ideas on how to keep them around?

Birdman

6:30 pm on Jun 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this one out. It uses the onsubmit event, instead of on click. Put the <script> in the <head> of the page and it should work.

<form name="form1" method="post" action="?" onsubmit="return disableSubmit();">
<input name="cont" value="Submit" type="submit">
</form>

<script type="text/javascript">
function disableSubmit(){
document.form1.cont.disabled = true;
document.form1.cont.value='Please wait...';
return true;
}
</script>

chadmg

6:42 pm on Jun 2, 2004 (gmt 0)

10+ Year Member



Right, it should work, but it doesn't. I hit the back button and it still says Submit and it's not disabled. Does IE reload the page when you go back to it? I don't see how it can since the form data is still there.

Birdman

10:35 pm on Jun 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hit the back button

Ah! I failed to catch that part in the first post.

Does IE reload the page when you go back to it?

Apparently it does. I put a simple alert() into the body tag and it pops up even when you go back.

So, knowing this, I think one way to do it would be to use the onload event of the body to test if one of your input fields has a value. If it does, then the user must have hit back.

<body onload="checkForBack(document.form1.somefield.value)">

function checkForBack(val){
if (val!= ''){
document.form1.cont.value='Please wait...';
document.form1.cont.disabled = true;
}
}

chadmg

12:30 am on Jun 3, 2004 (gmt 0)

10+ Year Member



you rock birdman, thanks.

unfortunately, both solutions are required. damn you ie!