I Love PHPMaker

... because it gets even more powerful and flexible!!

  • About
  • Terms and Conditions
  • Membership Options
  • Sitemap
  • Downloads
    • PHPMaker Extensions Download
    • PHPMaker Projects Download
    • PHP Report Maker Extensions Download
I Love PHPMaker » Tips and Trick » How to Set Focus on Next Input Field Using jQuery When Users Press Enter in Websites that Generated by PHPMaker 9.0.2
How to Avoid Displaying Database Connection String When Error Occurred in Websites that Generated by PHPMaker 9.0.3
How to Change Vertical-Align of CheckBox Item, View, Edit, and Copy Links from Middle to Top on List Page in Websites that Created with PHPMaker 8.0.3

June 11, 2012

How to Set Focus on Next Input Field Using jQuery When Users Press Enter in Websites that Generated by PHPMaker 9.0.2

This following trick will show you how to move cursor by using Enter key from one input field to the next input field on a form in websites that generated by PHPMaker 9. Instead of using Tab key, then we will use Enter key in order to set focus the next input field on a form while users are inserting or editing record. You can read the complete explanation from this article.

We will add our code (using jQuery) into the Client Scripts of PHPMaker. In other words, we will not modify any generated script files.

Updated on July 22, 2012: This customization has been implemented in PHPMaker version 9.0.3, it matches to each other, and as a result, it works properly.

Updated on September 5, 2012: This customization has been implemented in PHPMaker version 9.0.4, it matches to each other, and as a result, it works properly.

Updated on November 29, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.

Updated on February 9, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.

[hidepost]

  1. Open your PHPMaker project (.pmp) file using PHPMaker application.
  2. Click on Database icon on the toolbar, then click one of your desired table, and then click on the Code (Server Events, Client Scripts and Custom Templates) tab. Expand the following section: Client Scripts -> Table-Specific -> Add/Copy Page -> Client Script, and insert this following code into the right pane:

    $(document).ready(function() {

    var elem = $('input:visible', this).get(0);
    var textarea = $('textarea:visible', this).get(0);
    if (textarea && elem) {
    if (textarea.offsetTop < elem.offsetTop) { elem = textarea; } } var select = $('select:visible', this).get(0); // <-- replace 0 with 1 if you want to skip focus on the language selector! if (select && elem) { if (select.offsetTop < elem.offsetTop) { elem = select; } } if (elem) { elem.focus(); } $('input').keydown( function (event) { //event==Keyevent if(event.which == 13) { var inputs = $(this).closest('form').find(':input:visible:enabled'); var idx = inputs.index(this); if (idx == inputs.length - 1) { // handling submit button! } else { inputs.eq( inputs.index(this)+ 1 ).focus(); event.preventDefault(); //Disable standard Enterkey action } } }); $('select').keydown( function (event) { //event==Keyevent if(event.which == 13) { var inputs = $(this).closest('form').find(':input:visible:enabled'); var idx = inputs.index(this); if (idx == inputs.length - 1) { // handling submit button! } else { inputs.eq( inputs.index(this)+ 1 ).focus(); event.preventDefault(); //Disable standard Enterkey action } } }); $('radio').keydown( function (event) { //event==Keyevent if(event.which == 13) { var inputs = $(this).closest('form').find(':input:visible:enabled'); var idx = inputs.index(this); if (idx == inputs.length - 1) { // handling submit button! } else { inputs.eq( inputs.index(this)+ 1 ).focus(); event.preventDefault(); //Disable standard Enterkey action } } }); }); [/code]

  3. Next step, insert the following code for the Edit Page -> Client Script that located at the same level with the Add/Copy Page above:

    // Enter to move to next Input Field
    $(document).ready(function() {
    var elem = $('input:visible', this).get(0);
    var textarea = $('textarea:visible', this).get(0);
    if (textarea && elem) {
    if (textarea.offsetTop < elem.offsetTop) { elem = textarea; } } var select = $('select:visible', this).get(0); // <-- replace 0 with 1 if you want to skip focus on the language selector! if (select && elem) { if (select.offsetTop < elem.offsetTop) { elem = select; } } if (elem) { elem.focus(); elem.select(); } $('input').keydown( function (event) { //event==Keyevent if(event.which == 13) { var inputs = $(this).closest('form').find(':input:visible:enabled'); var idx = inputs.index(this); if (idx == inputs.length - 1) { // handling submit button! } else { inputs.eq( inputs.index(this)+ 1 ).focus(); inputs.eq( inputs.index(this)+ 1 ).select(); event.preventDefault(); //Disable standard Enterkey action } } }); $('select').keydown( function (event) { //event==Keyevent if(event.which == 13) { var inputs = $(this).closest('form').find(':input:visible:enabled'); var idx = inputs.index(this); if (idx == inputs.length - 1) { // handling submit button! } else { inputs.eq( inputs.index(this)+ 1 ).focus(); inputs.eq( inputs.index(this)+ 1 ).select(); event.preventDefault(); //Disable standard Enterkey action } } }); $('radio').keydown( function (event) { //event==Keyevent if(event.which == 13) { var inputs = $(this).closest('form').find(':input:visible:enabled'); var idx = inputs.index(this); if (idx == inputs.length - 1) { // handling submit button! } else { inputs.eq( inputs.index(this)+ 1 ).focus(); inputs.eq( inputs.index(this)+ 1 ).select(); event.preventDefault(); //Disable standard Enterkey action } } }); }); [/code] Please note that the difference between the code for Add and Edit section above is that we add the calling of select() below the calling of focus() in order to highlight all characters in the textbox for Edit mode.

  4. Repeat the step number two and three above for another tables you desire.
  5. Please note that if you want to skip focus on the language selector (if your web application is running the multi language feature), then change this code:

    var select = $('select:visible', this).get(0); // <-- replace 0 with 1 if you want to skip focus on the language selector! [/code] become: [code lang="php"] var select = $('select:visible', this).get(1); // <-- 1 = skip focus on the language selector! [/code]

  6. If you want to avoid adding that code in each and every table, then alternatively you can insert the related code above into C:\Program Files\PHPMaker 9\src\phpcodebase.xml file. Find this code:


  7. Make sure you have already checked (give tick mark) at Use jQuery and Local jQuery files items from Tools -> Advanced Settings of your PHPMaker application.
  8. Finally, don’t forget to save the changes, and re-generate your script files using PHPMaker as always.
[/hidepost]

Article by Masino Sinaga / Tips and Trick / autofocus, Enter, Input Field, jQuery, PHPMaker 9.0.2, PHPMaker 9.0.3, PHPMaker 9.0.4, PHPMaker 9.1.0, PHPMaker 9.2.0, select all, setfocus 12 Comments

How to Avoid Displaying Database Connection String When Error Occurred in Websites that Generated by PHPMaker 9.0.3
How to Change Vertical-Align of CheckBox Item, View, Edit, and Copy Links from Middle to Top on List Page in Websites that Created with PHPMaker 8.0.3

Comments

  1. keithh0427 says

    July 13, 2012 at 7:37 am

    Is there a way to do this without going to each and every table?

    Log in to Reply
    • Masino Sinaga says

      July 13, 2012 at 9:08 am

      Yes. Please read step 6 above.

      Log in to Reply
      • keithh0427 says

        September 13, 2012 at 7:46 pm

        Do we need to place both of the scripts in phpcodebase.xml?

        Log in to Reply
        • Masino Sinaga says

          September 14, 2012 at 9:19 pm

          No. Just choose one of the two methods above.

          Log in to Reply
  2. Thierry SEDGO says

    November 29, 2012 at 2:08 am

    Hi,
    My English very bad andi I’ve used google translation tool for this post.
    I’m a new registred member and don’t know where to post my question.
    Please can you help me… here is my question :
    How to fill form fields with data from a query. The query parameter receives the account number of a customer entered in the first field. I have a customer table containing all other customer information.
    Thanks a lot…

    Log in to Reply
    • Masino Sinaga says

      November 29, 2012 at 9:05 am

      You can see the example code from the generated *add.php file. For simplicity, I suggest you to generate the script from the simple table, for example, only two – three fields. Afterwards, customize the generated blank page and apply the code to it from the generated simple table above. Hope it helps.

      Log in to Reply
  3. Oscar says

    March 6, 2013 at 9:54 pm

    Could I add other Key to push the button “Add” or “Edit”? For example, F2 would do the same than the “Enter” key before your code. Thank you.

    Log in to Reply
    • Oscar says

      March 7, 2013 at 9:04 pm

      I have read again my question, and maybe it is not clear. If I use your code, the button doesn’t have a key to use and submit the form. How could I do if I use your code, for example, for what the page submit the form if I push the “F2” key (I think code ascii 113)?

      Log in to Reply
      • Masino Sinaga says

        March 15, 2013 at 11:41 pm

        Sorry for my delay response. Well, the answer of your question is: please implement the customization in the following article: How to Add “F2″ Key Press to Submit Form in Websites that Generated by PHPMaker 9.2.0.

        Log in to Reply
  4. Juan Manuel Garcia says

    June 28, 2018 at 12:33 pm

    Hi!
    I’m really lost!

    I have to two text fields and I want to the second field gets focused when Add Page is loaded.

    I’ve tried in Client Scripts->Table-Specific->Add/Copy Page->Startup Script this:

    document.getElementById(“x_cantidad”).focus();
    AND
    $(“x_cantidad”).focus();

    I’m using your extensions,

    Thanks.

    Log in to Reply
    • Masino Sinaga says

      July 12, 2018 at 5:51 pm

      Press [F12] from your browser, and check whether any Javascript error message displayed.

      Log in to Reply

Trackbacks

  1. How to Add “F2″ Key Press to Submit Form in Websites that Generated by PHPMaker 9.2.0 — I Love PHPMaker says:
    March 15, 2013 at 11:33 pm

    […] those of you who have implemented the customization that I wrote in the article How to Set Focus on Next Input Field Using jQuery When Users Press Enter in Websites that Generated …, then this following customization below is definitely for you! Yes, now we are going to add F2 Key […]

    Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • A New PHPMaker 2025 Project File Is Released
  • PHPMaker 2025 Demo Project File Is Released
  • Masino Extensions for PHPMaker 2025 Is Released!
  • A New PHPMaker 2024 Project File Is Released
  • PHPMaker 2024 Demo Project File Is Released
  • Masino Extensions for PHPMaker 2024 Is Released!
  • PHPMakerProjects.com, For Those Who Need PHPMaker Project Sample
  • A New PHPMaker 2023 Project File Is Released
  • PHPMaker 2023 Demo Project File Is Released
  • Masino Extensions for PHPMaker 2023 Is Released!

Search

Recent Comments

  • Masino Sinaga on Masino Extensions for PHPMaker 2024 Is Released!
  • Masino Sinaga on A New PHPMaker 2024 Project File Is Released
  • Masino Sinaga on PHPMaker 2023 Demo Project File Is Released
  • Edward Babatunde on PHPMaker 2023 Demo Project File Is Released
  • Edward Babatunde on Masino Extensions for PHPMaker 2024 Is Released!

Demo Website

  • Demo of I Love PHPMaker 2025 (MasinoExtensions).
  • Stock Inventory Management for PHPMaker 2025.

Another Demo

The following template are not available in this site (must be purchased separately)

  • PHPMaker v2018 Horizontal Vertical Template.
  • PHPMaker v2017 Horizontal Vertical Template.

Demo Explanation

Stock Inventory Management is the good project for your reference, since it uses the real example in the real world. Many useful features you can use from this project, such as how to add the Thousand and Decimal separator character, and also how to calculate multiple row in Grid-Add when End-Users are entering data into the Grid-Add mode.

Categories

  • Customize Template (103)
  • General (4)
  • PHP Report Maker (17)
  • PHP Report Maker Extensions (2)
  • PHPMaker Extensions (84)
  • PHPMaker Projects (7)
  • Tips and Trick (72)

Articles based on version

  • PHPMaker 2025
  • PHPMaker 2024
  • PHPMaker 2023
  • PHPMaker 2022
  • PHPMaker 2021
  • PHPMaker 2020
  • PHPMaker 2019
  • PHPMaker 2018
  • PHPMaker 2017.0.7
  • PHPMaker 12.0.7
  • PHPMaker 11.0.6
  • PHPMaker 10.0.5
  • PHPMaker 9.2.0
  • PHPMaker 8.0.3
  • PHP Report Maker 12

(c) I Love PHPMaker 2010 - 2025 by Masino Sinaga | WordPress | Log in | Back to top