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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.