JavaScript Form Validation

software development

#1

Hi,

I’m having problems with form validation using the following technique:

function IsFormComplete(formName)
{
var x = 0
var FormOk = true

while ((x < document.forms[formName].elements.length) && (FormOk))
{
if (document.forms[formName].elements[x].value == ‘’)
{
alert(‘Please enter the ‘+document.forms[formName].elements[x].name +’ and try again.’)
document.forms[formName].elements[x].focus()
FormOk = false
}
x ++
}
alert(FormOk); <–Tracing result
return FormOk;
}

----html

The script is returning false but still sending to my cgi script, pretty pointless. What am I missing? I want to keep it coded so that if the javascript is running on the clients browser it uses it, if not, the form will still work but send to the cgi script.

-Rich.


#2

OnSubmit=IsFormComplete("reqform")Is equivalent to

document.forms[formName].onsubmit = function() { IsFormComplete("reqform") }So what did you miss?

So in HTML you need

Don’t forget the single quotes!

:cool: Perl / MySQL / HTML CSS


#3

Ahhh, I tried that line but with double quotes.

All working now, thanks Atropos7.

-Rich.