Skip to main content
August 3, 2010
Answered

Setting to not include onSubmit / JavaScript?

  • August 3, 2010
  • 2 replies
  • 949 views

Hello,

I'm using the cfform tag (and cfinput) in my pages.  When looking at the generated code for one of the pages ('view source' in the browser), I noticed an onSubmit was added to the form tag with a call to some javascript.  The javascript is in the head section but is commented out.  Since this javascript isn't being used, I'm wondering if there's a setting to not add the onSubmit / javascript in my pages.

I'm using CF 9

Thanks

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    Is that what the OP meant?

    Those are HTML comments.  They have nothing to do with JavaScript.  All that's for is hiding JS from browsers that don't understand JavaScript.  The JS engine ignores them.

    --

    Adam

    2 replies

    Inspiring
    August 4, 2010

    Can you post this commented-out JavaScript?

    Or some CF code that - when we run it - demonstrates this happening?

    --

    Adam

    Inspiring
    August 4, 2010

    I can.

    This code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <cfsetting showdebugoutput="no">
    <body>
    <cfform action="abc.cfm" method="post">
    <cfinput name="x">
    </cfform>
    </body>
    </html>

    produces this html source code.  Note the html comments inside the script tags.  As I said earlier, the js still functions.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
    <script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    <!--
        _CF_checkCFForm_1 = 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;
            }
        }
    //-->
    </script>
    </head>

    <body>
    <form name="CFForm_1" id="CFForm_1" action="abc.cfm" method="post" onsubmit="return _CF_checkCFForm_1(this)">
    <input name="x" id="x"  type="text" />
    </form>

    </body>
    </html>

    Adam Cameron.Correct answer
    Inspiring
    August 4, 2010

    Is that what the OP meant?

    Those are HTML comments.  They have nothing to do with JavaScript.  All that's for is hiding JS from browsers that don't understand JavaScript.  The JS engine ignores them.

    --

    Adam

    Inspiring
    August 4, 2010

    The javascript is being used. Otherwise things like the required attribute wouldn't work.