Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript form validation in ColdFusion form

Status
Not open for further replies.

yuchieh

MIS
Jul 21, 2000
178
US
I have #getref.currentrow# as part of field name in the form.

<cfoutput query=&quot;getref&quot;>
<input type=&quot;text&quot; name=&quot;first_name#getref.currentrow#&quot; value=&quot;#first_name#&quot; size=&quot;25&quot; maxlength=&quot;75&quot;>
</cfoutput>

I would like to use javascript to check the form validation.

<cfset ttl = #getRef.recordcount#>

<script LANGUAGE=&quot;JavaScript&quot;>
function checkfields()
{
for (var i = 1; i <= <cfoutput>#Variables.ttl#</cfoutput>; i++)
{
if (document.reflist['first_name'+i].value == &quot;&quot;)
{ alert ('Please enter Reference's first name');
return false;}
}

else return true;
}
</script>

doesn't seem to work. any ideas? Thanks
 
Code:
function checkfields()
{ 
   for (var i = 1; i <= <cfoutput>#Variables.ttl#</cfoutput>; i++)
   {
      if (document.reflist['first_name'+i].value == &quot;&quot;)
      { 
         alert ('Please enter Reference's first name');
         return false;}
      }
   }
return true;
}
 
I think this the same as what I put in. still not working though.

Thanks
 
Is there any reason you aren't you using Cold Fusions's built in validation?

<cfinput type=&quot;text&quot; required=&quot;yes&quot; message=&quot;Please enter Reference's first name&quot; ...
 
Oh yeah, I guess in this case, I could use <cfinput> to check since all fields are text fields. However, I need to do the same thing on other pages which contain select boxes. I think javascript will work better.


Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top