Click to See Complete Forum and Search --> : activating submit button depending on field values


idiotbear
07-11-2003, 06:31 AM
hi

I want to have the submit button on my form disabled until a bunch of fields are filled out.

How do I express this? I'm fairly new to proper JS, so bear with me!

I was thinking along the lines of

function validate()

{
if document.forms[0].amount.value == "" ||
document.forms[0].account.value == "" ||
document.forms[0].startdate.value == "" ||
{
document.forms[0].submit.disabled = true }
else {
document.forms[0].submit.disabled = false }

}

I'm planning to call this on the onchange of each of the affected fields.

I know the above isn't right, but I don't know why - very inexperienced in JS logic and syntax.

I'd appreciate some help!

Exuro
07-13-2003, 07:30 PM
You need parenthesis around your conditions for your IF statement. You also need to get rid of that last pair of |'s.

function validate()

{
if ( document.forms[0].amount.value == "" ||
document.forms[0].account.value == "" ||
document.forms[0].startdate.value == "" )
{
document.forms[0].submit.disabled = true }
else {
document.forms[0].submit.disabled = false }

}

idiotbear
07-14-2003, 02:35 AM
thanks! that works beautifully now!

R