1

I have a number of auto-complete fields on my page with a submit button. I know on a text field there is an option called "Submit when Enter pressed" which works fine however this option is not available on these fields.

I have looked at a couple of other forum posts, this one i felt i nearly solved it however when i pressed any key the action fired which was wrong..

https://forums.oracle.com/forums/thread.jspa?threadID=2425583

Can anyone help? How can i submit a page on enter using an auto-complete field?

<script type="text/javascript" src="#APP_IMAGES#jquery-1.8.2.min.js">  
$('#P2_DOOR_NUMBER').keyup(function(e) {  
if (e.keyCode == '13')  
    $('#P2_GO').trigger('click');  
});  
</script>  
  • Oracle Version: Oracle version 10.2.0.4.0
  • Full APEX version: Application Express 4.1.1.00.23
  • Browser(s) and version(s) used: Internet Explorer 7 & 8
  • Theme: Simple Red Template(s): The standard templates with the Simple Red theme.
tomlogic
  • 11,489
  • 3
  • 33
  • 59
Blob
  • 541
  • 3
  • 20
  • 38

1 Answers1

2

Can you not simply use JQuery to bind your input field ? :

$('#YOUR_ITEM_ID').keyup(function (e) {
    if (e.keyCode === 13) {
        apex.submit({...});
    }
});

Of course you can do it using a dynamic action.

Yann39
  • 14,285
  • 11
  • 56
  • 84
  • Thats similar to the following post which i tried and failed to get working. - http://stackoverflow.com/questions/9937791/apex-how-to-submit-page-when-enter-pressed-on-field When i tried it, it triggered on every key stroke rather than just on enter, it never knew when Enter was pressed so the return value was always false. – Blob Oct 22 '12 at 07:14
  • Are you sure you have wrote your code correctly, I use it for a long time and it works fine on all major browsers. Using `if (e.keyCode === 13)` it should submit only when enter is pressed. Maybe on IE you may have some problem, see [link](http://stackoverflow.com/questions/1750223/javascript-keycode-values-are-undefined-in-internet-explorer-8). If it still not working maybe you can show us some code ? – Yann39 Oct 22 '12 at 07:29
  • I think i must be doing something incorrect. I added the JQuery by the help of the following link: http://www.oracleapplicationexpress.com/tutorials/66 and then in the HTML header i added the following code (updated in initial post) – Blob Oct 22 '12 at 09:57
  • Ive got it working. I used a dynamic action to hold the JQuery and works a dream, thank you :-) – Blob Oct 22 '12 at 10:24
  • As you are using APEX 4.1, JQuery should be loaded by default, you should not need to load it again. And you should not use `if (e.keyCode == '13')` but `if (e.keyCode === 13)` ! It may be the source of your problem, `e.keyCode` is not a string, the == saves you because it do an implicit conversion. Strict equality operators are always preferred. – Yann39 Oct 22 '12 at 12:08