[jQuery] Ok... one last effort to make this work... help!
Rick, with modifications below this works for me. If you need to make it
more abstract (i.e., for more than one text input) you can start from here
and add a piece at a time--I always find it easier to debug using a
functioning version to start rather than starting from errors and working
backwards...
Hope it helps convince you to stick with jQuery -- after a short learning
curve it makes life SO much simpler!
paul
HTML doc:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test bed</title>
<script src="/shared/js/jquery.js"
type="text/javascript"></script>
<script type="text/javascript">
$(function() { //jQuery makes this run when the page is
loaded and ready
$("#Principal").blur(function(){
//assign a blur event to the input
$.post("debug.cfm", {principal:
$("#Principal").val()}, function(data){
// append what you get back to the element with ID =
Result after clearing its contents
$("#Result").empty().append(data);
}); // closes post
}); // closes blur
}); // closes document.ready
</script>
</head>
<body>
<Form id="ValidatePrincipal" Name="ValidatePrincipal">
<table>
<tr>
<td>
Result: <Span id="Result"></span>
</td>
</tr>
<tr>
<td>
Principal: <INPUT ID="Principal" Name="Principal"
Type="Text" Value="" Size="20" Class="TextInput01">
</td>
</tr>
<tr>
<td>
Interest: <INPUT ID="Interest" Name="Interest"
Type="Text" Value="" Size="20" Class="TextInput01">
</td>
</tr>
</table>
</Form>
</body>
</html>
CFM Page:
<CFSET Principal_Error_Message = "">
<CFIF Len(Trim(Form.Principal)) and Not
IsNumeric(REReplace(Form.Principal, "[.$,]","","All"))>
<CFSET Principal_Error_Message = "Please enter a valid
dollar amount.">
<CFELSEIF Not Len(Trim(Form.Principal))>
<CFSET Principal_Error_Message = "Please enter a value for
the Principal.">
</CFIF>
<CFOUTPUT>#Principal_Error_Message#</CFOUTPUT>
-----Original Message-----
From: discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com] On
Behalf Of Rick Faircloth
Sent: Tuesday, March 13, 2007 6:34 PM
To: 'jQuery Discussion.'
Subject: [jQuery] Ok... one last effort to make this work... help!
Hi, all...
I've been tinkering with jQuery for about 3 weeks now and while
I've made some progress and gotten some things to work, I'm
stuck on validation and I've got to get it working so I can do something
that makes money!
Anyway... here's what I've got. If anyone could give me the advice I need
to get this working I'd be very grateful...
I'm trying to run validation on each form field of a form on blur. Right
now
I'm just working on one form field.
I've got my page with the validation code (trying to use $post) and my form.
I've also set up my processing page (.cfm). However, nothing seems to be
happening with the processing. The form just acts like a regular form.
Firebug isn't complaining of any js errors...
Here are the 3 parts involved:
jQuery:
<script type="text/javascript">
function ValidatePrincipal(){
var Params = {};
$("input:text").each(function(){
Params[$(this).attr("name")] = $(this).val();
});
// "post" the form. The Params object mimics form fields
$.post("callpage_Validate_Mortgage_Inputs.cfm", Params,
['Principal'], function(data){
// this is the processing function.
// append what you get back to the element with ID = Result
after clearing its contents
$("#Result").empty().append(data);
} // closes post function
); // closes ( after .post
} // closes { after ValidatePrincipal()
</script>
Form HTML:
<body>
<Form id="ValidatePrincipal" Name="ValidatePrincipal">
<table>
<tr>
<td>
Result: <Span id="Result"></span>
</td>
</tr>
<tr>
<td>
Principal: <INPUT ID="Principal" Name="Principal"
Type="Text" Value="" Size="20" Class="TextInput01"
onBlur="ValidatePrincipal">
</td>
</tr>
<tr>
<td>
Interest: <INPUT ID="Interest" Name="Interest"
Type="Text" Value="" Size="20" Class="TextInput01">
</td>
</tr>
</table>
</Form>
</body>
And finally, the .cfm processing code:
<CFIF Value="Principal">
<CFSET Principal_Error_Message = "">
<CFIF Len(Trim(Form.Principal)) and Not
IsNumeric(REReplace(Form.Principal, "[.$,]","","All"))>
<CFSET Principal_Error_Message = "Please enter a valid
dollar amount.">
<CFELSEIF Not Len(Trim(Form.Principal))>
<CFSET Principal_Error_Message = "Please enter a value for
the Principal.">
</CFIF>
<CFCONTENT
Reset="Yes"><CFOUTPUT>#Principal_Error_Message#</CFOUTPUT>
</CFIF>
</CFIF>
Any hints why this is not working?
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/