PDA

View Full Version : RE-Enable form button if authentication fails after disabling?



monaya
03-03-2009, 10:00 PM
I'm disbaling a submit button on submit and validating some info. I'm trying to enable it again if the user fails authentication to re-enter data. Here is my code. Seems to work in Safari, IE but not Mozilla.


<script language="javascript">
function submitform()
{
if (document.getElementById("code").value != "4343")
{
window.alert("incorrect code. try again.");
document.getElementById("btnsubmit").value = "Send Feedback";
document.getElementById("btnsubmit").disabled = false;
return false;
}
else
{
document.form1.submit();
}
}
</script>

<input type="button" name="btnsubmit" id="btnsubmit" value="Send Feedback" onClick="this.value='Please wait...';this.disabled = true;submitform();"/>


it worked once, then when I rechecked it, the button stays disabled after a failed authentication? I hate when that happens because I implement the code all over!

Nile
03-03-2009, 10:40 PM
Replace:


onClick="this.value='Please wait...';this.disabled = true;submitform();"

With:


onClick="submitform(this);"


And change your javascript to:


function submitform(me) {
if (document.getElementById("code").value != "4343") {
window.alert("incorrect code. try again.");
me.value = "Send Feedback";
if(me.disabled) {
me.disabled = false;
}
return false;
} else {
document.form1.submit();
}
}

monaya
03-03-2009, 11:11 PM
If I remove:


onClick="this.value='Please wait...';this.disabled = true;submitform();"

then even my original code works actually.

I wanted to disable the submit button upon submit and display a please wait message. The part I wanted was to return the button back to its original state if the user fails the authentication statements.

Nile
03-04-2009, 12:58 PM
Replace:


onClick="this.value='Please wait...';this.disabled = true;submitform();"

With:


onClick="submitform(this);"



Please read my whole post. When you call the submitform function, it will make the value please wait, and disable it.

monaya
03-09-2009, 01:11 AM
Here's an example. Only Mozilla gives me trouble. The button is not reenabled after hitting OK in the alert:
http://monaya.bravehost.com/javascriptfun/disablebutton.htm