Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 609 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clean way to prevent enter button submitting a form

#1
I've seen a lot of Javascript solutions to do this, but I'm sure there must be an easier way.

I have a really simple form - one multiline textbox and a submit button. I want the user to be able to submit "formatted" text (i.e. like an email, with paragraphs, new lines etc)

However, when the user hits Enter to put in a carriage return it submits the form.

I'm there there must be a property or something that controls this, as this must be a common issue. Javascript as a solution seems a bit too complex.
Reply

#2
Did u try this? -

[To see links please register here]

Reply

#3
You could set the [DefaultButton][1] on the Form or the Panel surrounding your TextBox to an invisible(display:none) Button. On this way you have full control what happens when user hits enter-key without (browser-dependent) Javascript. If you don't handle its onclick-event, the enter-key will be suppressed.

[To see links please register here]


[1]:

[To see links please register here]

Reply

#4
The following code solved my issue:

[To see links please register here]


<script type="text/javascript">
//Stop Form Submission of Enter Key Press
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type == "text")) { return false; }
}
document.onkeypress = stopRKey;
</script>

Put this in the master page or just in the pages that you want.
Reply

#5
Set the **UseSubmitBehavior** property on the **submit button** to **FALSE**. (found the solution [here][1])


[1]:

[To see links please register here]

Reply

#6
In HTML front end just replace body tag with body onkeydown = "return (event.keyCode!=13)
Reply

#7
Use Submit behavior didn't work for me but this

$(function () {
$(window).keydown(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
});
})
worked for me
Reply

#8
Similar to the answer of Max, but showing complete code:

function EnterKeyFilter() {
if (window.event.keyCode == 13) {
event.returnValue = false
event.cancel = true
}
}
window.addEventListener('keydown', EnterKeyFilter)
</script>

Also similar to other answers, of course, otherwise it wouldn't work, but possibly simpler.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through