Prevent CFFORM from submitting
Copy link to clipboard
Copied
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,
^_^
Copy link to clipboard
Copied
Leave the submit button off or <input type="Submit" disabled>
Copy link to clipboard
Copied
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.
^_^
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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.
^_^
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Preventing the enter key from working onSubmit will submit the form. Preventing the enter key onKeyDown prevents the form from being submit.
^_^
Copy link to clipboard
Copied
Yeah, I gotta agree with Dan. Users get seriously pissed when you break the functionality they're used to.
That being said - are you _ever_ submitting the form? Or is it just posting data via Ajax for the save?
If you never submit the form - then remove the action from the form tag, don't have a <input type='submit' /> and use a link or other some such device to post via Ajax.
If you shared more code this would be easier for us all...
Copy link to clipboard
Copied
cfsilence wrote:
Yeah, I gotta agree with Dan. Users get seriously pissed when you break the functionality they're used to.
That being said - are you _ever_ submitting the form? Or is it just posting data via Ajax for the save?
If you never submit the form - then remove the action from the form tag, don't have a <input type='submit' /> and use a link or other some such device to post via Ajax.
If you shared more code this would be easier for us all...
This is for an internal web app for a large corporation, not a publically available site, so the users kind of expect certain things.
The form should not actually submit, the action has already been removed, in IE7 it will submit anyway - even without the action or an input submit.
It is set to do something similar to Google's instant search - starts retrieving data with each keystroke. But the ENTER key was screwing things up.
^_^
Copy link to clipboard
Copied
Well, I hate to say this, but the enter key does submit the form on Google instant. Go try it, you'll see the page actually refreshes.

