Skip to main content
Inspiring
November 16, 2010
Answered

Required cfinput working, but not working

  • November 16, 2010
  • 2 replies
  • 903 views

The title is a little cryptic, but I wasn't sure how better to describe this!

I'm working in CF8 with DW CS4.  Here's some pertinent code snippets:

++++++++++++++

<cfform name='D71_Entry_Form' method='post' action="index.cfm?fuseaction=validate_D71_data">

...

<cfinput type = 'text'
             name = 'customer_number'
             size = '6'
             style = 'font-size: 12px;'

             message = 'Customer Number is Required!'
             required = 'Yes'>
...

<input type="submit" name="validate_entered_values" value="Submit the Transaction"
      onclick="location.href='index.cfm?fuseaction=validate_D71_data'">

++++++++++++++

On clicking the submit button, the error message 'Customer Number is Required!' is shown (as expected) and when I click "OK", instead of remaining on the current screen to re-enter the data, I am sent to the "validate_D71_data" fuse action (not as expected).

What did I fail to code correctly?

    This topic has been closed for replies.
    Correct answer Daverms

    Change your onClick attribute as,

    <input type="submit" name="validate_entered_values" value="Submit the Transaction"
          onclick="return submitData();">

    And add this JS Snippet at the top of your page,

    <SCRIPT LANGUAGE="JavaScript">
        function submitData()

        {
            if(confirm ("Are you sure you want to submit your data?")){
                return true;
            }else{
                return false;
            }
        }
    </SCRIPT>

    HTH

    2 replies

    DavermsCorrect answer
    Inspiring
    November 16, 2010

    Change your onClick attribute as,

    <input type="submit" name="validate_entered_values" value="Submit the Transaction"
          onclick="return submitData();">

    And add this JS Snippet at the top of your page,

    <SCRIPT LANGUAGE="JavaScript">
        function submitData()

        {
            if(confirm ("Are you sure you want to submit your data?")){
                return true;
            }else{
                return false;
            }
        }
    </SCRIPT>

    HTH

    Community Expert
    November 16, 2010

    If you want JS to run prior to form submission, you should use the form's onsubmit event handler attribute rather than the submit button's onclick event handler attribute.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

    GSA Schedule, and provides the highest caliber vendor-authorized

    instruction at our training centers, online, or onsite.

    Read this before you post:

    http://forums.adobe.com/thread/607238

    Dave Watts, Eidolon LLC
    Inspiring
    November 16, 2010

    How come you have an onclick event handler and a form action going to the same place?  I would say your onsubmit event handler is what's causing your problem, rather than letting the form submit "normally".

    --

    Adam