If I connect to my form's onSubmit event, how can I find out which button on the form was used for submit? Or, if the form was submitted by pressing the Enter key on an element, how can I find out which element was in focus?
I cannot rely on ExplicitOriginalTarget property of the event object, as this is Mozilla-specific.
Any suggestions?
Don't use submit buttons, you can easily run a script when a button is pressed, in that script you may submit the form (simply call the forms .submit() method), that way you will easily know what button was pressed, and any submit not originating from your code must then of course originate from the user pressing enter.
Related
I have a complex form with many different types of fields and a submit button. As far as I'm aware, a form can be submitted by clicking the submit button, by pressing Enter in certain form fields (for example text input fields), and on mobile devices by pressing the submit button on the on-screen keyboard. There may be more ways to submit the form that I'm not aware of.
I would like to register a separate (JavaScript) submit handler that applies when the form is submitted only within a certain section of the form. Pressing the submit button or submitting the form from a form field outside of the special section should call the regular submit handler, but submitting the form from a form field inside the special section should call another handler. One particular challenge in my case is that some of my form fields are rendered by third-party React components, and I don't have the possibility to control their DOM.
I could come up with ideas that go in the following directions:
Somehow find out from which form element the form was submitted, and check whether that element is within the special section. The problem is that I have not been able to find a way to detect the originating form field on the submit event.
Use nested forms and put the special form group in its own form with its own submit button and submit event handler. The problem is that there seems to be no supported way of nesting forms in HTML.
Use the form attribute on each input field within the special form group and point it to a separate form with its own submit button and submit event handler. I am assuming that this would produce the desired behaviour. Unfortunately, I cannot add this attribute to all input fields, since I don't control their DOM.
React to keydown events with key set to Enter. The first problem is that pressing Enter only submits the form in certain cases. For example, pressing enter in a text input submits the form, but pressing enter in a textarea or a button input does not. In some cases such as a file input (which sometimes consists of a text field and a button) I'm not even sure and the behaviour between browsers is probably inconsistent. So I don't know under what conditions even to call the submit handler. The second problem is that I assume that this does not take other submission methods into consideration, such as the submit key on touch devices.
Is there a good way to catch the form submission from within a certain section of the form only?
I want to fill submit form on a website page using cefSharp:
cefSharp1.ExecuteScriptAsync("document.getElementById('Author').value='Me'");
But button submit not active, because this form checks if keys have been pressed, there are attached events: main.keyup=onTextChange($event,index,id)
how can i simulate call them? Thanks.
Is there any way to disable the elements of a form onload, except the submit button.
It means that form in JSP page will be loaded with the existing data from backend but user should not be able to edit data. User can only use the submit the button.
I can do it manually by disabling each and every field manually but I am wondering if there is some way to disable all fields at a time, since there are many fields in the form in JSP page.
You can use :not() selector
$('form :not([type=submit])').prop('disabled',true);
I have a text box and Javascript attached to a button. I have the onkeyup event linked to the same method as the button.
I want to be able to type in the text box and hit enter and execute my Javascript. Instead, lotus thinks I want to submit a form, hijacks what I am doing, and returns "Form Processed". It is very obnoxious.
What can I do to avoid Lotus doing this?
If you don't ever want to do a standard submit to Domino, then use a Page design element instead of a Form.
But if you do want to submit a standard Domino form, you can set the onSubmit event on the form to false in order to stop the browser from doing automatic submits. But you won't be able to use a simple submit button if you do that. You will have to explicitly call document.forms[0].submit().
You need to have a function that handles the submit event for that form and have it return false.
The easiest way to do this is to add this attribute to your form tag
<form onsubmit="return false;">
I have a standard form for a user login.
When I input the username and password, then press enter it gives the search result. The search text box is in the same page.
I want to set the focus on the submit button. The enter key issue only exists in IE? What can I do to solve this problem?
You can focus anything with the focus() javascript method. This has nothing to do with PHP.
document.getElementById('ID_Name_Of_Your_Button').focus();
Submit button must be defined in the same form tag as the other form elements. And submit will be fired on what form you are focused while pressing [enter].
You don't need to focus any submit buttons in your case.
And the document content is needed for the more exact answer of course.