?
Solved

Cross-field validation

Posted on 2008-11-19
3
Medium Priority
?
318 Views
Last Modified: 2013-12-24
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?
0
Comment
Question by:sailing_12
3 Comments
 
LVL 16

Assisted Solution

by:duncancumming
duncancumming earned 800 total points
ID: 22996693
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
 

Author Comment

by:sailing_12
ID: 22997388
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
 
LVL 2

Accepted Solution

by:
mtgenus earned 1200 total points
ID: 22998242
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question