I want to use JavaScript to detect the number of times a key (for example, the A key) is pressed. Once it reaches a preset number (say 10 for this example), it will trigger two events: 1. Change the background color of a cell in a table from white to black. 2. A split-second (e.g., .01 second) later, submit the form on this page. I can't have the user hit the ENTER key to submit the form, so the JavaScript script will need to do this. Thank you very much for your help!
Do this: 1. Use the javascript 'onkeypress' event (ASCII code for the 'A' key) to increment a variable each time it is pressed 2. Create a function that executes the change color part using <div> when the variable == 10 (your number) 3. Create a second function that executes using the 'setinterval' event after the variable >= 10 (your number) 4. On the second function use the getElementById('formname').submit() to submit the form Hope this helps! ~imozeb
I appreciate your help, but as a JavaScript newbie, I don't know how to implement your suggestions in actual code. It's kind of like a doctor telling a beginning nursing student to "Just put in an IV and give some vasopressors." How do you insert the IV? How do you give the vasopressor?
Go to w3schools.com and search for javascript and htmldom. They have a lot of great tutorials. You should be able to find everything you need there. But here is some of the code you can't find in the javascript section. To submit a form type: getElementById('formname').submit() Code (markup): Replace 'formname' with your form name. To change the color you use the getElementById('divname') and you change the .style part. It should all be there on w3schools.com though. Try to code it and if it gives you errors or you have specific questions post your code here and I'll try to help you with it.