3 Replies Latest reply on Jul 9, 2007 3:29 PM by brettskiii

    Coldfusion generated javascript. Can you move to external file?

    brettskiii
      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;
        • 1. Re: Coldfusion generated javascript. Can you move to external file?
          c_wigginton Level 1

          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.
          • 2. Coldfusion generated javascript. Can you move to external file?
            iKnowKungFoo Level 1
            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.
            • 3. Re: Coldfusion generated javascript. Can you move to external file?
              brettskiii Level 1
              Thank you both, this clears it up :)