Jump to content

Submit button won't disable (and I've search the forum)


coder71

Recommended Posts

I've seen the posts on this, but the submit button is still not disabling on my page. The code is supposed to check the form for errors and then disable the submit button. It catches the errors, but won't disable the submit. What happens is that if everything is verified, it looks like the form posts and for a brief second the submit button disables. Then the form refreshes without actually posting the data. Here's the JS in the head:

 

function disableForm(theform) {

if (document.all || document.getElementById) {

for (i = 0; i < theform.length; i++) {

var tempobj = theform.elements;

if (tempobj.type.toLowerCase() == "submit")

tempobj.disabled = true;

}

return true;

}

}

 

 

function validRequired(formField,fieldLabel)

{

var result = true;

 

if (formField.value == "")

{

alert('Please enter a value for the "' + fieldLabel +'" field.');

formField.focus();

result = false;

}

 

return result;

}

 

function validateForm(theForm){

if (!validRequired(theForm.cardnumber,"Credit Card Number")){

return false;

}

 

if (!validRequired(theForm.cardexpmonth,"Expiration Month")){

return false;}

 

if (!validRequired(theForm.cardexpyear,"Expiration Year")){

return false;}

 

disableForm(theForm);

return true;

}

 

Here's the form line:

 

<form name="addjob3" action="<? PHP_SELF; ?>" method="POST" onsubmit="return validateForm(this)">

Here's the submit button:

 

<input type="submit" name="submitp" value="Submit">

 

I've been trying this for literally a whole day. I can't get it and it's driving me nuts! I'd really appreciate someone helping me with this. I'm good with PHP but don't know much about JS at all.

oops... i meant to say "What happens is that if everything is verified, it looks like the form posts and for a brief second the submit button disables<b>, but then it re-enables and then</b> the form refreshes without actually posting the data.

 

This is holding me up on completing this project. I've searched everywhere. Can anyone please help me with this?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.