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;">
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 need to submit a form with full refresh per CSJS in an event.
I know the solution to click the submit button. But is there a way to do it directly with JavaScript on client?
Thank you!
My workaround is to place a button with SSJS in a hidden div and then triggering it via CSJS. The button may do whatever you want, e.g. submit the form (save the datasource).
The cleaner approach would be to set the $$xspsubmitid with CSJS and then submitting the form. A possible way is described here: http://xpages.info/XPagesHome.nsf/Entry.xsp?documentId=88065536729EA065852578CB0066ADEC
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.
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.
I'm debugging a weird problem with two simlar search forms - when user types some search criteria in a text box and hits enter, one form returns results and another just reloads. And it happens only in IE - FF treats both forms as expected. I suspect that hitting enter is triggering onclick for one of the search buttons in one case and something else in another.
How do I find what form element caused submit event?
Thanks,
Andrey
Sounds like the single textbox form bug in IE.
To get around it, you can use Javascript to handle the enter key press, or just insert a blank hidden textbox. Lame, I know.
I suspect that hitting enter is triggering onclick for one of the search buttons in one case and something else in another.
Yes. Browsers may, largely at their whim, treat enter as clicking on a submit-button, just submitting a form, or nothing. Put general form submission stuff in form.onsubmit, rather than an onclick on the first submit button.
You could sprinkle your form elements with onclick events to set a hidden form variable with a different value per element, then sniff the results either with a DOM inspector or through something like Fiddler.
There may be a way to simply have a form onsubmit() event that you can extract the triggering element from the event object, but I'd have to dive into the docs to see if this is possible... if I get chance I'll do some looking.
I think I may help you much If you provide your two forms code. However, check to see for the following submit button code:
<input type="submit" value="Submit">
When you use this, then when you press Enter among the corresponding form, the form will be submitted. If you wish to check something before submitting you can use JavaScript Function like the following:
<input type="button" onclick="javascript_function_name();" value="Submit">
Thanks. If this can not help you, please express the situation more briefly.