an**********@ho tmail.com (Techy) writes:
I have two fields in my form so called : invoice and cash
Now I want to validate this form on the client side with the help of
javascript in such a way that if one of these fields is empy an alert
box should pop up notifying the client.
if one is empty: alert.
Now if one is empty it should let the form to process
if one is empty: continuer.
Since I don't know exactly what you want, I'll give some code
that is easily changed:
To validate a function, always use this way to call the validation function:
---
<form ... onsubmit="retur n validate(this)" >
---
The function itself is then:
---
function validate(form) {
var cashEmpty = form.elements['cash'].value == "";
var invoiceEmpty = form.elements['invoice'].value == "";
if (cashEmpty && invoiceEmpty) {
alert("Fill in at least one of the fields: Cash or Invoice.");
return false;
}
return true;
}
---
If this (error of both are empty) is not what you want, you only
need to change the condition of the if (and the alert message).
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'