Skip to main content
WolfShade
Legend
April 19, 2011
Question

Prevent CFFORM from submitting

  • April 19, 2011
  • 2 replies
  • 3258 views

Hello, everyone.

I've tried disabling a CFFORM by using ' onLoad="this.disabled = true;"' and ' onLoad="this.submit.disabled = true;"' and other things, but no matter what I do I cannot seem to prevent a CFFORM from being submit (there is no submit button; there's a text link that runs some JavaScript when needed).

How can I either disable the CFFORM or prevent it from being submit?

Thanks,

^_^

    This topic has been closed for replies.

    2 replies

    ilssac
    Inspiring
    April 19, 2011

    You don't "DISABLE" a form.

    If you don't want the form submitted you RETURN false from any function that would submit the form.

    VERY SIMPLE example.

    <form...>

    <input type="submit" onClick="return False">

    </form>

    WolfShade
    WolfShadeAuthor
    Legend
    April 19, 2011

    Sorry.. I was in a big rush when I was trying to explain things.

    The issue was due to the ENTER key submitting the form when I didn't want it to (the <a> was supposed to handle submitting the form, but the ENTER key would do it, anyway.)

    The solution was to use JavaScript / onKeyDown(event) to prevent the ENTER key from working (there are no textareas or anything else that would require use of the ENTER key - just one simple input/text and three radio buttons - so disabling the ENTER key is sufficient.)

    Thank you for your input and advice, everyone.

    ^_^

    Inspiring
    April 19, 2011

    What you did is not necessarily the best idea.  Causing the browser to work differently than expected creates upleasant user experiences.

    Since you have all this javascript written anyhow, you could always call it with the form's onsubmit event.

    Inspiring
    April 19, 2011

    Leave the submit button off or <input type="Submit" disabled>

    WolfShade
    WolfShadeAuthor
    Legend
    April 19, 2011

    LyndonPatton wrote:

    Leave the submit button off or <input type="Submit" disabled>

    I've tried disabling a CFFORM by using ' onLoad="this.disabled = true;"' and ' onLoad="this.submit.disabled = true;"' and other things, but no matter what I do I cannot seem to prevent a CFFORM from being submit (there is no submit button; there's a text link that runs some JavaScript when needed).

    There isn't a submit button.

    ^_^

    Inspiring
    April 19, 2011

    I can't understand why you would submit a

    form using a link, but if you must....

    The form element, which cfform inherits from, does not have a disabled property so onLoad="this.disabled = true;" is not valid. See http://www.w3schools.com/html/html_forms.asp for a property, object, and method list for the form element.

    If your link is doing your form submit work then it needs to be be disabled until your condition becomes true. The <a> link element also does not have a disabled property; you would want to set it's display property to none untill the condition is met.

    If you shared more code this would be easier...