Hi all
I'm working on a PHP/MySQL asset management system for storing my clients' computer information, and something tricky has come up. I have an HTML form, with fields such as "Client name", "Address" and so on, and the way it currently works is that if you enter part of a client name in the appropriate field, eg "mac", and hit the Find button, a Javascript function does some pseudo-AJAX, talks to a PHP script and returns a list of clients with that substring.
The form does not have a "submit" button, but it does have three buttons which, respectively, "find", "add" and "clear" values, using different Javascript routines. They all work fine.
However, what I want to do is to add "return key" behavior, so that, if you enter the string in the "name" field, and then, instead of going to the Find button, hit "Return", it runs the "find" function as before.
This does not work. I set up an "onKeyPress" event on the "name" field to catch the return key - it does so, but I believe that something else is also catching the return keypress, because even without the added onKeyPress, if I hit "return", the page unexpectedly reloads. Hence, when I set up my function, the existing behavior runs at the same time as my new behavior, and the AJAX fails.
Hope that makes sense. So, my question is, does anyone have experience in reprogramming "return key" behavior in an HTML form, and is there a straightforward solution to my problem?
many thanks!
Matt
I'm working on a PHP/MySQL asset management system for storing my clients' computer information, and something tricky has come up. I have an HTML form, with fields such as "Client name", "Address" and so on, and the way it currently works is that if you enter part of a client name in the appropriate field, eg "mac", and hit the Find button, a Javascript function does some pseudo-AJAX, talks to a PHP script and returns a list of clients with that substring.
The form does not have a "submit" button, but it does have three buttons which, respectively, "find", "add" and "clear" values, using different Javascript routines. They all work fine.
However, what I want to do is to add "return key" behavior, so that, if you enter the string in the "name" field, and then, instead of going to the Find button, hit "Return", it runs the "find" function as before.
This does not work. I set up an "onKeyPress" event on the "name" field to catch the return key - it does so, but I believe that something else is also catching the return keypress, because even without the added onKeyPress, if I hit "return", the page unexpectedly reloads. Hence, when I set up my function, the existing behavior runs at the same time as my new behavior, and the AJAX fails.
Hope that makes sense. So, my question is, does anyone have experience in reprogramming "return key" behavior in an HTML form, and is there a straightforward solution to my problem?
many thanks!
Matt