• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Coldfusion generated javascript. Can you move to external file?

Guest
Jul 09, 2007 Jul 09, 2007

Copy link to clipboard

Copied

Hi,

Coldfusion when you use cfform etc puts a lot of javascript into my html page (see example beliw.

Is there someway I can tell coldfusion to include this as an external file as opposed to including it in the head section?

Many thanks,


Example of coldfusion added stuff..


_CF_checkCFForm_3 = function(_CF_this)
{
//reset on submit
_CF_error_exists = false;
_CF_error_messages = new Array();
_CF_error_fields = new Object();
_CF_FirstErrorField = null;


//display error messages and return success
if( _CF_error_exists )
{
if( _CF_error_messages.length > 0 )
{
// show alert() message
_CF_onErrorAlert(_CF_error_messages);
// set focus to first form error, if the field supports js focus().
if( _CF_this[_CF_FirstErrorField].type == "text" )
{ _CF_this[_CF_FirstErrorField].focus(); }

}
return false;
}else {
return true;
TOPICS
Advanced techniques

Views

514

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 09, 2007 Jul 09, 2007

Copy link to clipboard

Copied


The short answer is no.

CFFORM does use external JavaScript files where it can (CFIDE/scripts), however the JavaScript included at the top of the page is dynamic in nature and tied directly to the form and its elements. Generation of the scripts is internal to the code of ColdFusion and isn't accessible for modification.

You could certainly write your own validation routines using only external JavaScript, but you wouldn't have the CFFORM ease of use and would have to resort to creating your own custom tag form and form element wrapper tags.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 09, 2007 Jul 09, 2007

Copy link to clipboard

Copied

Actually, you _can_ move it to an external file.

Use CFFORM to create the form and the validation code. When you do this, the javascript gets compiled and rendered with every page request. If the form doesn't change, then the javascript never changes. Once you've reached the final version of the form, you can copy the javascript to an external .JS file and reference it in the HTML.

In order to keep CFFORM from re-creating the Javascript in that page, swap out the CFFROM and CFINPUT tags for normal FORM and INPUT tags, using the CFFORM generated HTML as a reference for any events like onChange, onClick or onSubmit that CFFORM created.

This will cut down on the amount of processing that CF does just to render the javascript code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 09, 2007 Jul 09, 2007

Copy link to clipboard

Copied

LATEST
Thank you both, this clears it up 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation