Link to home
Start Free TrialLog in
Avatar of rivkamak
rivkamakFlag for United States of America

asked on

adding to verification function

I have a verification function that checks my form fields if they have value
. if it doesn't it runs a string of things.

right now i have it to check 1 field.
function validateField(fieldname, labelname, longname) {
	longname = typeof longname !== 'undefined' ? longname : fieldname;
	
	if(document.getElementById(fieldname)) {
		if(document.getElementById(fieldname).value == "" || document.getElementById(fieldname).value == $('#' + fieldname).attr('placeholder') ) {
			 themessage = (themessage + longname+ '\n');
				
		}
	}
}

Open in new window

How can I use the same verification to if 2 fields are blank.
like this: if (document.form1.model.value=="" && document.form1.model1.value=="" ) {
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rivkamak

ASKER

How would I pass this using the function
if (document.form1.model.value=="" && document.form1.model1.value=="" )
validate(?????);
My code will handle both fields if you give them an ID and call them like

   message += validateField("FieldID1","","long name");
   message += validateField("FieldID2","","long name");
my question is how I should call the function to begin with.
It is called for you,

It is assigned to the submit of the form

Just replace your code with mine and fill in the missing stuff

"FieldID1","here","and here");