Submitting a form with enter key causing strange problems

I am having a very strange problem with a webapp I am currently developing. I am using JSF 1.2 along with Facelets and RichFaces. I have coded a workflow/wizard 4-step process, and on some pages I have 4 submit buttons that all call different actions on the page. The users thought it would be useful to have the enter key submit the form, so I followed some online resources to trap a keypress using javascript, looking for the enter keycode and calling document.getElementById("elementName").click(). This works fine most of the time. Sometimes, though, it seems as if an entire new session is being created, and odd behavior starts happening. For example, my page will only include 2 of the 4 facelets on the screen -or- I will get NullPointerExceptions for objects that I know have been created in the session bean I am currently using -or- I will get a duplicate form Id after trying to re-submit the page. Could the javascript click simulation not be submitting all of the form elements or is the enter key also acting like its default action (the form submission) in addition to the "click"? I'm really at my wit's end here (plus it's nearly 3 AM, that never helps things). All of the buttons being clicked are standard h:commandButtons. There is some setTimeout logic included to disable the buttons on the page to prevent double clicks (I cannot disable them onsubmit because disabled buttons don't pass the right values, perhaps that's causing it, but if so, clicking the buttons with the mouse would cause that issue too, right?)
I am not posting the code (yet), but if anyone wants to take a look see and see if I am doing something really abhorrently wrong, I'm more than willing to, I'm just curious if anyone has had problems regarding javascript submission of forms via the click() method. Clicking the button does not exhibit this type of behavior. Just as a side note: I am doing different things with the enter key depending if a modal window is open (the enter key closes the modal if it's up, and if not, it submits the form via a button click).
Any help is much appreciated, if anyone has any inkling about where I should start looking for answers it would be really helpful.
Thank you.

edfrost wrote:
Could the javascript click simulation not be submitting all of the form elements or is the enter key also acting like its default action (the form submission) in addition to the "click"?My guess is the second of these. You need to suppress the event handling after programmatically clicking the button.

Similar Messages

  • Submitting form with Enter key

    Hello,
    in standard html form, when you have form with submit button, the enter key when any form element is selected submits the form.
    This is very convenient for users, so I want this with UIX forms. I know it is possible (I have one form where it is working), but I can't get it working anywhere else.
    This code works:
    <uix:form method="post" name="newRoleForm">
    <uix:inlineMessage prompt="Role name">
    <uix:textInput name="newRoleName" />
    <uix:spacer width="15" />
    <uix:submitButton text="Create" formName="newRoleForm" />
    </uix:inlineMessage>
    <uix:formValue name="jboEvent" value="newRole" />
    </uix:form>
    When I copy this code to another page, it does not work...
    Can somebody help, please?

    I've studied the HTML generated by UIX and it has following bugs and misfeatures:
    1. Misfeature: Submitting with Enter works ONLY if there is exactly one text field in the form (no submit button is actually needed), as Brian Stoler wrote. I don't understand reason for this.
    2. Bug: UIX generates javascript function "_submitOnEnter" which is called as event handler for "onKeyPress" event. But this function is erroneously generated multiple times, once for each form in the page. Browsers (Mozilla and IE) use the latest implementation. This function is different for forms with one text field and for forms with more text field, but only the first one can do the job. As a consequence of this, Enter can submit the form only if the last form on a page has single text field (which is for example not the case of search form with single field above another form...)
    Tested with UIX 2.1.7 in JDeveloper 9.0.3.3, using UIX as JSP tag library.
    Workaround:
    1. Use Opera browser: it submits form with enter key even if there is no submit button (this does not work for the first text field in the form, because it has "onkeypress" event handler).
    2. Implement this feature by hand yourself, if you really need it (see below).
    3. Use accessKey: allows to submit form with Alt+<key> combination (followed by Enter with IE).
    Implementing Enter key submits with Javascript:
    1. Put the following function to the header (or to javascript library):
    function enter(e, frm) {
    var kc;
    if(window.event) kc=window.event.keyCode;
    else if(e) kc=e.which;
    else return true;
    if(kc==13) {
    submitForm(frm,1);
    return false;
    Function copied from UIX (C).
    2. Add this event handler to each input element:
    onKeyPress="return enter(event, 'formName');"
    It is obvious that this is error prone, but it works with all browsers...
    Will this be fixed in future versions?
    Why only form with one text field can be submitted?

  • How to select tree node with enter key instead of mouse click

    hia i have tree in forms 10g i can get node value when i click mouse on node but i want same with enter key which is not working any idea.
    thanx

    I'm afraid you have hit Bug 4509399
    If you have metalink access you should check Note:331369.1
    This bug has been around for the 10g R2 10.1.2.0.2 base release, which was propagated from Installing Patch 9.0.4.2 or from 10g R1 base release. You need to apply the latest patch or a one-off fix Patch 4509399
    Tony

  • Submitting a form with an anchor tag

    How could I do this? I'm using a self submitting html form with JSP. I want an anchor tag to send some parameters to update the content of the page.

    Hi,
    You can use query string to pass the parameter values to the page.
    Ex:
    firstname and secondname are the two parameter values which you can pass it to the page.
    <ahref=http://website2.com/action?val1=' firstname' & val2='secondname'> Page2</a>
    if you click on the 'Page2' then those values are pass to the corresponding page
    Regards
    Reegan

  • Submit a Form in IE with Enter key.

    Hi all,
    I have a Form with a Get attribute, a textfield and a search
    (submit) button.
    When I press the Enter key in my keyboard, the form is not
    submited in I.E. (i'm using IE 7).
    When I click the button with the mouse, it works.
    In Firefox, all (keyboard and mouse) works.
    How can we workaround this issue?
    Thanks

    oicram wrote:
    > Please, I need an answer here. I have deeply search over
    the internet and I only found something about .js or hidden fields,
    but its all vague...
    http://www.webreference.com/programming/java_dhtml/chap8/2/2.html
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Strange issue with "Enter" key in Vista on Satellite P300-225

    A few weeks ago, I don't recall exactly when, Windows Vista on my Satellite P300-225 started to pass an incorrect scancode to applications when the Enter key is pressed. It always sends the scancode of the Keypad Enter key, even when I hit the one in the alphanumeric part of the keyboard. It did work correctly some time ago, but suddenly, it just started acting like this. No remapping of any keys.
    Since there are quite a few programs that act different on these two keys, this has become quite an annoying issue.
    The strangest part of it is, that the problem seems to be somehow related to Windows Vista, since the keys are correctly reported on Linux.
    If anybody has a clue, please, let me know.

    Yes, it almost certainly is a keymapping issue related to Vista. Reinstalling Vista isn't a way to go, it's not worth the effort (the recovery DVDs would comletely wipe out everything from my harddisk so I'd have to move all my data away and then restore, reinstall Linux et cetera). I'll give a try to uninstalling the keyboard in safe mode though.
    Anyway, it almost looks like some Windows update is responsible for this, since I have automatic updates enabled and it installs something everytime I boot it. I don't know about any program I installed before this happend that could possibly alter the mappings. (...and the registry key used for this is empty.)

  • Problem with Enter key and JOptionPane in 1.4

    Hi,
    I had a problem with an application I was working on.
    In this application, pressing [Enter] anywhere within the focused window would submit the information entered into the form that was contained within the frame.
    The application would then try to validate the data. If it was found to be invalid, it would pop up a JOptionPane informing the user of that fact.
    By default, pressing [Enter] when a JOptionPane is up will activate the focused button (in most cases, the [OK] button) thus dismissing the dialog.
    In JDK 1.3 this worked fine. But in JDK 1.4, this has the result of dismissing the dialog and opping it up again. This is because the [Enter] key still works on the frame behind the JOptionPane and thus tries to validate it again, which results in another invalid dialog msg popping up.
    The only way to get out is to use the mouse or the Esc key.
    Now, in the application I put in a workaround that I was not very happy with. So, to make sure it wasn't the application itself, I created a test which demonstrates that it still misbehaves.
    Here it is.
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.AbstractAction;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.KeyStroke;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    import javax.swing.WindowConstants;
    * @author avromf
    public class FocusProblemTest extends AbstractAction
         private static JFrame frame;
         public FocusProblemTest()
              super();
              putValue(NAME, "Test");
         public void actionPerformed(ActionEvent e)
              JOptionPane.showMessageDialog(frame, "This is a test.");
         public static void main(String[] args)
              FocusProblemTest action= new FocusProblemTest();
              try
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              catch (Exception e)
                   e.printStackTrace();
              frame= new JFrame("Test");
              frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
              Container contents= frame.getContentPane();
              contents.setLayout(new FlowLayout());
              JTextField field= new JTextField("Test");
              field.setColumns(30);
              JButton  button= new JButton(action);
              KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true);
              button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(enterKey, "test");
              button.getActionMap().put("test", action);
              contents.add(field);
              contents.add(button);
              frame.pack();
              frame.setVisible(true);
    }Does anyone have any solution to this problem?

    I know that focus management has changed alot.
    Based on my experimentation a while back, in 1.4 it still believes that the JFrame is the window in focus, even though a JOptionPane is currently in front of it (unless I misinterpreted what was going on). Thus, the frame seems to get the keyboard event and re-invoke the action.
    A.F.

  • Submiting HTML Forms with JavaFX Webview

    I've long been searching for a good web robot framework. And I also need a gui for my robot.
    So w/ the advent of JAVAFX Webengine it seemed my needs have been met finally. Specially because on the webview tutorial here , Alla Redko says: "+It supports user interaction such as navigating links *and submitting HTML forms*+".
    But after looking at the api it doesn't seem that webengine supports submiting forms, only loading pages w/ the load() method. I guess I could populate the form fields and submit them w/ executeScript() but that's just sloppy.
    Is there a way to actually submit forms w/ webengine? Are there plans to implement this feature, analogous to the load() method?
    Thanks,
    JC

    Yea, as I mentioned in the first post, I could do all that w/ JS but it's just sloppy, since I'm using Java language, not JS.
    The finding certain fields part is easy w/ the Document model and xpath, it's the populating the fields and submiting the form along w/ its hidden input fields that is the missing part.
    Does anyone know if these things are planned for the future of Webview/Webengine?You can already do this in Java today using the existing APIs if you so wished.
    import javafx.application.Application;
    import javafx.beans.property.*;
    import javafx.beans.value.*;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.*;
    import javafx.scene.layout.*;
    import javafx.scene.web.*;
    import javafx.stage.Stage;
    import org.w3c.dom.*;
    import org.w3c.dom.html.*;
    public class WebViewFormPost extends Application {
      public static void main(String[] args) { launch(args); }
      @Override public void start(Stage stage) {
        final TextField fxUsername = new TextField();
        final TextField fxPassword = new PasswordField();
        final BooleanProperty loginAttempted = new SimpleBooleanProperty(false);
        final WebView webView = new WebView();
        final WebEngine engine = webView.getEngine();
        engine.documentProperty().addListener(new ChangeListener<Document>() {
          @Override public void changed(ObservableValue<? extends Document> ov, Document oldDoc, Document doc) {
            if (doc != null && !loginAttempted.get()) {
              if (doc.getElementsByTagName("form").getLength() > 0) {
                HTMLFormElement form = (HTMLFormElement) doc.getElementsByTagName("form").item(0);
                if ("/oam/server/sso/auth_cred_submit".equals(form.getAttribute("action"))) {
                  HTMLInputElement username = null;
                  HTMLInputElement password = null;
                  NodeList nodes = form.getElementsByTagName("input");
                  for (int i = 0; i < nodes.getLength(); i++) {
                    HTMLInputElement input = (HTMLInputElement) nodes.item(i);
                    switch (input.getName()) {
                      case "ssousername":
                        username = input;
                        break;
                      case "password":
                        password = input;
                        break;
                  if (username != null && password != null) {
                    loginAttempted.set(true);
                    username.setValue(fxUsername.getText());
                    password.setValue(fxPassword.getText());
                    form.submit();
                    System.out.println("Submitted login for user: " + username);
        engine.getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {
          @Override public void changed(ObservableValue<? extends Throwable> ov, Throwable oldException, Throwable exception) {
            System.out.println("Load Exception: " + exception);
        GridPane inputGrid = new GridPane();
        inputGrid.setHgap(10);
        inputGrid.setVgap(10);
        inputGrid.addRow(0, new Label("Username: "), fxUsername);
        inputGrid.addRow(0, new Label("Password: "), fxPassword);
        Button fxLoginButton = new Button("Login to Oracle Forums");
        fxLoginButton.setOnAction(new EventHandler<ActionEvent>() {
          @Override public void handle(ActionEvent t) {
            if (notEmpty(fxPassword.getText()) && notEmpty(fxPassword.getText())) {
              loginAttempted.set(false);
              engine.load("https://forums.oracle.com/forums/login!withRedirect.jspa");
        final VBox layout = new VBox(10);
        layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
        layout.getChildren().addAll(
          new Label("Enter your Oracle Web Account credentials"),
          inputGrid,
          fxLoginButton,
          webView
        stage.setScene(new Scene(layout));
        stage.show();
      private boolean notEmpty(String s) {
        return s != null && !"".equals(s);
    }Personally, I think using JavaScript via engine.executeScript calls in combination with jquery might be a less messy solution (as I don't like writing against the raw dom apis), but I understand that there are valid reasons why you might prefer to use a Java only solution.
    https://gist.github.com/jewelsea/3077942 "Embeds jQuery in a document loaded into a WebView."

  • Submit OA page with Enter key in custom page

    Hello All,
    I have one custom page with 20+ fields and two submit buttons to do different processing.
    On this page, if enter key is pressed then I need to submit the form i.e. invoke processing corresponding to one of the submit button.
    I know that at field level I can bind enter key event. But for that I need to write same code 20 times for all 20 fields.
    Do we have any simple way to implement submit if enter key is pressed in any of the fields?
    Any help will be highly appreciated.
    Thanks,
    Ritesh

    Hi Ritesh,
    Not sure but you will want to try implementing the method mentioned by Anil using "OAPageLayoutBean" to get the enter key handle for all the fields in a page.
    i.e. try with
    OAPageLayoutBean page = pageContext.getPageLayoutBean();
    Hashtable params = new Hashtable(); 
        params.put ("Go", "value1");
        page.setAttributeValue(OAWebBeanConstants.ON_KEY_PRESS_ATTR, new OABoundValueEnterOnKeyPress(pageContext,
                                          "DefaultFormName", // enclosing form name
                                          params, // request parameters
                                          false, // client unvalidated
                                          false)); // server unvalidatedinstead of
    OAMessageTextInputBean HelloName = (OAMessageTextInputBean)webBean.findChildRecursive("HelloName");
             Hashtable params = new Hashtable(); 
             params.put ("Go", "value1");
             HelloName.setAttributeValue(OAWebBeanConstants.ON_KEY_PRESS_ATTR,
             new OABoundValueEnterOnKeyPress(pageContext,
                                          "DefaultFormName", // enclosing form name
                                          params, // request parameters
                                          false, // client unvalidated
                                          false)); // server unvalidatedand pls update the result.
    regards,
    Anand

  • Tabular Form with updateable keys??? Help!!

    I have been trying to set up a timesheet/scheduling package using my PT job as a real world framework from which to pull ideas. The job is at a concert venue.
    The idea is to be able to schedule an event, then add existing employees and add the appropriate employee to that event.
    I have the tables already setup: EVENTS which consists of 'event_name', event_time_and_date, unique_event_id(priKey), etc... Employees which is first,last,empnum(priKey),etc.... And most importantly a Schedule table which is empnum(priKey,foreign to employees), eventid(secKey,foreign(sp?) to unique_event_id), time in, time out, etc....
    Everything is great except that I cannot add an employee to an event using the Tabular Form as the empnum primary key needs to be defined by a dropdown LOV(my criterea) and the eventid needs to be defaulted to the passed in value. It seems the Form is not setup to operate that way. I have included a link to my mock-up on oracle's free HTMLDB space so that the lucky individual who decides to aide this lost soul can see what I'm on about. I have been able to do it via single drop downs, but that is one person at a time. The table is the best way visually to see who has, and has yet to be added to an event.
    http://htmldb.oracle.com/pls/otn/f?p=38803:1
    Click on schedule and choose 'Assign Employee' and click the event in January to get to the 'Add Employee' page.
    The number present on the page should be hidden but is visible for debugging purposes. It is the unique event ID that the SQL bind refers to filter the list to the event in question.
    Thank you very much,
    brux2dc

    From the trigger code I see a new PK being generated. Just so I am understanding what is going on, the new pk will in no way be used except to keep the tabular form in order.
    The data in the intersection table will look like this:
    EMPNUM(PK) | EVENTID(PK)
    1 | 1001
    1 | 1002
    1 | 1003
    2 | 1001
    2 | 1003
    3 | 1002
    The tabular form will enter data so that an already existing eventid will be associated with multiple empnums. The eventid is passed to a hidden textbox. This is where the fixed eventid comes form and the empnums become the only variable per new row.
    What should happen when I click on Add Row is that a new row appears with the eventid already set as PK1 and the LOV with EMPNUM as PK2. So before insert the screen would have:
    EMPNUM(PK) | EVENTID(PK)
    1 | 1001
    2 | 1001
    3 | 1001
    5 | 1001
    I just wanted to clarify further what my intent is. I appreciate all your help so far.
    brux2dc

  • Satellite A200 with enter key stuck

    Hello to all.
    I own an A200 Satellite laptop and i have a very strange problem. The enter key is stuck. I have tested it with no keyboard at all but the key remains stuck. I also tested to unplug the touch panel and the function keys but still enter key is stuck !
    Any ideas?
    Thank you.

    I agree. I checked for water damage but it seems clean. I just thought to post it in case anyone had the same problem before. Anyway thank you all for bothering read the post.
    P.S. Where can i download a bios update from? Thank you.
    Message was edited by: johnyp

  • JSF 2.0 ajax : Submit form  on Enter key press in h:inputTextarea

    Dear All,
    I am new to JSF 2.0 . Just wanted to submit the form in ajax when a user hits the "Enter": key while typing
    in the h:inputTextarea . I would be very thankful to you guys if you help me out.
    Thanking in advance!

    I found the problem and a solution :-) The missing piece of the puzzle was the id attribute for the form tag. After some debugging of the JSF JavaScript I found the solution.
    The JavaScript function response(request, context) is invoked to handle the server response. Inside this function the doUpdate(element, context) is invoked.
    The doUpdate() function is doing the modification of the DOM. The function doUpdate() is two times invoked for a response. The first time the html elements are updated.
    The second time the view state hidden field is updated or created but only under the following condition:
    Comment in the JavaScript source code of the jsf.js
    //Now set the view state from the server into the DOM
    //but only for the form that submitted the request.If the forms of the both side haven't the same id the form can't be found on the second page.
    In the following way it is working:
    page1.xhtml
    <h:form id="myform">
            <h:commandLink value="Go to page 2" action="page2">
                <f:ajax render="@all" execute="@all"/>
            </h:commandLink>
    </h:form>
    .....page2.xhtml
    <h:form id="myform">
                <h:commandLink value="Go to page 1" action="page1">
                    <f:ajax render="@all" execute="@all"/>
                </h:commandLink>
    </h:form>So always set an explicit id for each JSF tag.

  • Submitting a form with customize subject line

    Hi
    I would like some help with Submitting a form via E-mail with a customize subject line. I want the subject like to be the First name of the person which they would have to enter in the form. Is this possible?
    Thanks

    Look at this previous thread:
    http://forums.adobe.com/message/5615207#5615207
    The script would look something like:
        //Place into a submit button     
         var cSubLine = this.getField("FirstName").value;       //Replace FirstName with the name of the field on your form
         this.mailForm({
         bUI: true,
         cTo: "[email protected]",
         cSubject: cSubLine,

  • Wrong values submitted when submitting a form with javascript

    Hi guys, I know this aint a struts forum, but I did not know where else to go. So here goes..
    I have the following code in my jsp
    <logic:iterate id="ex" name="myForm" property="users">
    <html:multibox property="deleteUsers">
    <bean:write name="ex" property="userId"/>
    </html:multibox>
    </logic:iterate>
    I have about 10 users of which 5 have already been marked for deletion from another action. So basically, the above tag renders 10 rows with a checkbox in the beginning to select users to delete. Also 5 of them have been checked already, I mean when the form is loaded. So checkboxes 1, 4, 5, 8, 10 have already been checked. Now I have a link on which goes like this
    Select None. On this I call a javascript which does the following
    function uncheckAll() {
    for (i = 0; i < 10; i++) {
    document.myForm.deleteUsers.checked = false;
    This unchecks all my checkboxes.
    Now comes the problem. I am submitting the form using a javascript which is invoked on clicking on the submit link using document.myForm.submit(); The problem is the deleteUsers property in myForm still retains the old values. If the checkboxes are unchecked no values should be submitted for this and the deleteUsers array should be empty. Can anyone help me out on this.
    Thanks.

    Checkboxes only submit a value when they are "on"
    They submit nothing if they are not selected.
    The problem comes - do you interpret no checkbox values as "clear all values" or "leave the values alone"? Struts assumes the latter.
    Your form is probably being kept in session?
    Try implementing the reset() method of your action form and set its property to be equivalent to no checkboxes selected.

  • CF7 - sending a form using "Enter" key

    As I wrote in the subject, i've goit a question.
    How can I send a form using the "Enter" key. When I push the
    Enter nothing happneds. Can someone help me?

    OK. My mistake. In normal HTMLform there is no problem.
    I've got the Flash form
    [code]
    <cfform name="register" format="Flash" skin="haloBlue"
    width="300" height="200" timeout="999999999"
    action="index.html">
    <cfinput type="hidden" name="skrypt" value="#skrypt#">
    <cfinput type="hidden" name="save" value="True">
    <cfinput type="Text" name="username"
    label="Użytkownik: " required="Yes" message="Proszę
    podać użytkownika" size="20">
    <cfinput type="Password" name="pass" label="Hasło: "
    required="Yes" message="Proszę podać hasło"
    size="20">
    <cfinput type="submit" name="submit" value="Loguj">
    </cfform>
    [/code]

Maybe you are looking for