Jason Kretzer/STAR BASE Consulting Inc. wrote:
OK, I have it now. I used :
//for the submit button
onSubmit=validateFields();
//then in validateFields I got the form and checked each field for a
value and then submitted when all had a value, like so:
var thisForm = document.forms[0];
if(thisForm.comp.value == '')
{
alert('Company name is required.');
thisForm.comp.focus();
return;
}
else if(thisForm.desc.value == '')
{
alert('Short description is required.');
thisForm.desc.focus();
return;
}
else if(thisForm.addr.value == '')
{
alert('An address is required.');
thisForm.addr.focus();
return;
}
///....etc.
else
{
thisForm.method.value = 'POST';
thisForm.action = 'FormProcessor?action=a';
thisForm.submit();
}
Hmmm. What ever happened to Once and Only Once? ;) Try this instead:
function validate()
{
var thisForm = document.forms[0];
var fields = new Array(
{ name: "comp", description: "Company name" },
{ name: "desc", description: "Short description" },
{ name: "addr", description: "An address" },
// ...etc.
);
for ( var i = 0; i < elements.length; i++ )
{
var element = thisForm.elements[fields[i].name];
if ( element.value == '' )
{
alert( fields[i].description + ' is required.' );
field.focus();
return;
}
}
thisForm.method.value = 'POST';
thisForm.action = 'FormProcessor?action=a';
thisForm.submit();
}
Hope that helps. :)
- Eric
|