Cross-field validation

Simply put, I have a CF form on which are fields for an order number and confirmation number (which are not the same). I need to require that at least one of these fields is filled in before the form is submitted, and I'd like to run this validation client-side. Anyone know how?
sailing_12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

duncancummingCommented:
My javascript might be slightly off, but you get the general idea.
<script type="text/javascript">
function validate(this)
{
	if (this.ordernumber == '' && this.confirmationnumber == '')
		return false
	else
		return true
}
</script>
 
<form onSubmit="return validate(this)">
	order number  <input type="text" name="ordernumber"><br>
	confirmation number <input type="text" name="confirmationnumber">
	
	<input type="submit">
</form>

Open in new window

0
sailing_12Author Commented:
That's great except that I am using the Coldfusion <cfform> tag, which generates all of the html form markup and page javascript on the fly. So the form is already calling the CF native JS validation script (onsubmit="return _CF_checkCFForm_1(this)").

While I could use the <cfhtmlhead> CF tag to inject the JS function into the page head, I don't know how or if I can manipulate the onSubmit JS function call to call an additional function beyond what CF is outputting.

??
0
mtgenusCommented:
duncancumming is right, just change it for cfform as I did in the code snippet, and coldfusion will add the validate() function to the bottom of its _CF_checkCFForm_1.
<cfform onSubmit="javascript:return validate(this)">
        order number  <cfinput type="text" name="ordernumber"><br>
        confirmation number <cfinput type="text" name="confirmationnumber">
        
        <cfinput type="submit">
</cfform>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.