By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

javascript validation for mixed form

P: n/a
ll
Hi,
I am working with a page that has both cfform elements and 'plain
html' form elements. In particular, I am needing to validate my
textarea form field and my email text field. On one of my html pages,
I have been using a great javascript validation script; however, I am
wondering if I can use that in a coldfusion page? I've included the
javascript I'd been using before.
Thanks for any help you can provide,
Regards,
Louis
In the cfform tag, I included this call:
<cfform action="#cgi.script_name#" method="Post" name="NewItemForm"
onSubmit="return checkWholeForm(this)" >
The javascript in the head is listed below:
-----
<script language="JavaScript">
// news headline/email subject
function checkEmailSubject (strng) {
var error="";
if (strng == "") {
error = "Please enter an Email Subject/News Headline.\n\n";
}

// news/email content
function checkContent (strng) {
var error="";
if (strng == "") {
error = "Please enter Email/News Content.\n\n";
}

// email
function checkEmail (strng) {
var error="";
if (strng == "") {
error = "Please enter your email address.\n\n";
}

//filter for ou/ouhsc domains
var emailFilter2=/.@(ou|ouhsc)\.edu$/i
if (!(emailFilter2.test(strng))) {
error="Please enter a valid email address with either ou or ouhsc
domain.\n\n";
}
//end domain filter

var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strng))) {
error = "Please enter a valid email address.\n\n";
}
else {
//test email for illegal characters
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (strng.match(illegalChars)) {
error = "The email address contains illegal characters.\n
\n";
}

}
return error;
}
<!-- Begin check form script, which refers to above -->

function checkWholeForm(NewItemForm) {
var why = "";
why += checkEmail(NewItemForm.Email1.value);
why += checkEmailSubject(NewItemForm.EmailSubject.value);
why += checkContent(NewItemForm.Content.value);
if (why != "") {
alert(why);
return false;
}
return true;
}
// -->
</script>
<!-- End form validation script -->

Apr 26 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ll said the following on 4/26/2007 4:50 PM:
Hi,
I am working with a page that has both cfform elements and 'plain
html' form elements.
There is no such thing as a "cfform element" in HTML. What you use on
the server is irrelevant. What is relevant is what the browser gets. So,
post a sample URL to a generated page and not Cold Fusion code.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 27 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.