cfinput required="yes" and inline javascript conflict

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default cfinput required="yes" and inline javascript conflict

    Has anyone experienced a situation where inline Javascript is causing Cold
    Fusion's native error reporting to fail. I have a script that tests 2 select
    boxes to make sure the user has selected a value, if not, generate an alert.
    My regular cfinput fields are set to required="yes" message="myMessage". But
    if I have an onSubmit function in tag <CFFORM>, the form will submit and no
    alert will be generated for the required cfinput fields. Take out the
    onSubmit function and CF alerts as expected. I started noticing this after
    upgrading to CF 7. Below is my code:

    <script language="javascript" type="text/javascript">
    <!--
    function CheckForm() {
    if (document.forms[0].Country.selectedIndex < 1) {
    alert("Please select a country.");
    return false;
    }
    else if (document.forms[0].STATE1.selectedIndex < 1) {
    alert("Please select a state.");
    return false;
    }
    }
    //-->
    </script>

    <cfform name="form" action="mreg_pck.cfm" method="post" onSubmit="return
    CheckForm();">
    MyForm
    </cfform>


    bforce Guest

  2. Similar Questions and Discussions

    1. "Page" and "Rect" props of the Field prop in Javascript API
      Page property of the Field property in Javascript Acrobat API returns an array of pages that this field exists in. On the other hand, "rect" property...
    2. how i use <cfinput type="file" ...> in cfformtype="flash
      hi, I want to use the <cfinput type="file" ...> in cfform type="flash . But How ? Regards Prashant
    3. CFINPUT type="radio" w/ "value" requires "label"
      On a Flash form, when you specify type='radio' and value='whatever', the value of the 'value' attribute will be displayed as a label if no 'label'...
    4. #22197 [Fbk->NoF]: "inline" functions cannot use "static" identifier
      ID: 22197 Updated by: sniper@php.net Reported By: j_vanveelen at jea dot ca -Status: Feedback +Status: ...
    5. #22197 [Asn->Fbk]: "inline" functions cannot use "static" identifier
      ID: 22197 Updated by: sniper@php.net Reported By: j_vanveelen at jea dot ca -Status: Assigned +Status: ...
  3. #2

    Default Re: cfinput required="yes" and inline javascript conflict

    Also - Does anyone know what's up with cfxchange.com? Bought a custom tag
    from them yesterday and the site broke. Never go the tag and thier site is
    down today. I thought it was a pretty active site for CF developers but all
    of the posts in thier forum look to be at least a year old. Hope I didn't
    get ripped!


    "bforce" <bforce@poultryegg.org> wrote in message
    news:d5gf4e$70o$1@forums.macromedia.com...
    > Has anyone experienced a situation where inline Javascript is causing Cold
    > Fusion's native error reporting to fail. I have a script that tests 2
    > select boxes to make sure the user has selected a value, if not, generate
    > an alert. My regular cfinput fields are set to required="yes"
    > message="myMessage". But if I have an onSubmit function in tag <CFFORM>,
    > the form will submit and no alert will be generated for the required
    > cfinput fields. Take out the onSubmit function and CF alerts as expected.
    > I started noticing this after upgrading to CF 7. Below is my code:
    >
    > <script language="javascript" type="text/javascript">
    > <!--
    > function CheckForm() {
    > if (document.forms[0].Country.selectedIndex < 1) {
    > alert("Please select a country.");
    > return false;
    > }
    > else if (document.forms[0].STATE1.selectedIndex < 1) {
    > alert("Please select a state.");
    > return false;
    > }
    > }
    > //-->
    > </script>
    >
    > <cfform name="form" action="mreg_pck.cfm" method="post" onSubmit="return
    > CheckForm();">
    > MyForm
    > </cfform>
    >

    bforce Guest

  4. #3

    Default Re: cfinput required="yes" and inline javascriptconflict

    I had the same problem with calling javascript from the onsubmit attribute in
    the cfform tag when trying to validate a field in the form. I got around this
    by using the onvalidate attribute of the cfinput or cfselect or any other cf
    form type tag. But I don't think you have to use it on the form you provided.
    Here is what I would do with your form:

    <cfform name="form" action="mreg_pck.cfm" method="post">
    <cfselect query="GetCountries" name="Country" display="country_name"
    value="country_code" required="yes" message="A country is required">
    </cfselect>
    <cfselect query="GetStates" name="STATE1" display="state_name"
    value="state_code" required="yes" message="A state is required">
    </cfselect>
    </cfform>

    Hope this helps, but let me know if you were looking for something else!

    CF_DAWG Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139