Js header and submit problems

Hi

I’m new to javascript and have managed to pick up bits and pieces of information off the forum. I have the following code in my jsheader:

function checkForm() {

//if the Reference no field is blank

if (document.forms[0].IC_RefNo.value == “”) {

alert(“Please enter the Complaint Reference Number.”);

document.forms[0].IC_RefNo.focus();

return false;

}

//if the Complaint Received date is blank

if (document.forms[0].IC_DateRec.value == “”) {

alert(“Please enter the Complaint Received Date.”);

document.forms[0].IC_DateRec.focus();

return false;

}

//if the Product Group field is blank

if (document.forms[0].IC_ProdGroup.value == “”) {

alert(“Please select the Product Group address.”);

document.forms[0].IC_ProdGroup.focus();

return false;

}

//if the Product field is blank

if (document.forms[0].IC_Prod.value == “”) {

alert(“Please select the relevant product.”);

document.forms[0].IC_Prod.focus();

return false;

}

//if the Fault is blank

if (document.forms[0].IC_Fault.value == “”) {

alert(“Please select the relevant Fault.”);

document.forms[0].IC_Fault.focus();

return false;

}

//if the Batch Number is blank

if (document.forms[0].IC_BatchNo.value == “”) {

alert(“Please enter the appropriate Batch Number.”);

document.forms[0].IC_BatchNo.focus();

return false;

}

//if the Shade Number is blank

if (document.forms[0].IC_ShadeNo.value == “”) {

alert(“Please enter the relevant Shade Number.”);

document.forms[0].IC_ShadeNo.focus();

return false;

}

//if the Area Meterage is blank

if (document.forms[0].IC_Area.value == “”) {

alert(“Please enter the Area Meterage.”);

document.forms[0].IC_RefNo.focus();

return false;

}

//all is well, so submit the document

document.forms[0].submit()

}

and I’ve put the following code into a submit button on the form:

return checkForm()

but when I load the form in Internet Explorer the button does not appear. I’ve tried putting the code in a save and submit action button but that disappears and if I just user @command ([FileSave]) in the action button it just ignores the validation. Any help would be greatly appreciated. I figure its something basic but its beyond me now.

Thanks in Advance

Adam

Subject: js header and submit problems

Also, your logic is a bit off here. Your are calling your validate in your submit button to return the value of the function checkForm. That value will return either True, or the onsubmit function will submit the form. What you should do instead is something like this

if(checkForm()){

return true;

}else{

return false

}

Then in checkForm, build your error message up as an array and display them all together (so you don’t have a ton of attempts to validate it field by field, but this is a separate issue). When the validation PASSES, however, simply return true. In this way, the calling code in your onSubmit (or in the button, though onSubmit is a better place to put it) handles all of the decisions on whether or not the form is submitted. Your button code can simply be the formula @command([filesave]); @command([fileclosewindow])

Subject: js header and submit problems

Hi,

Hard to say what’s going on, I thought I might suggest that you could always just use passthru HTML to create the button if this doesn’t work?

HTH

Andrew.

Subject: RE: js header and submit problems

Hi Andrew

Thanks for the prompt response. It worked.

I now have a problem with three of the fields I’m validating. they are dialog lists and even when I select an option from the list it keeps prompting me to put information in those fields.

Regards

Adam

Subject: RE: js header and submit problems

You can not validate all field types in the same way. To validate a dialog list

var f = document.forms[0];

if (f.FIELDNAME.options[f.FIELDNAME.selectedIndex].text == “WHATEVER”)

Subject: RE: js header and submit problems

Also, keep in mind that radio button and checkbox “fields” on the web use yet another method for validation. Google “validate checkbox” or “validate radio button” for examples. There are also examples in this forum.

Subject: js header and submit problems

Hi,

Hard to say what’s going on, I thought I might suggest that you could always just use passthru HTML to create the button if this doesn’t work?

HTH

Andrew.