471,337 Members | 794 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Javascript dynamically change onkeydown event?

eboyjr14
I have this UserScript for Grease monkey. but I can't get the onleydown event to fire in FIREFOX only. I've looked everywhere!


Expand|Select|Wrap|Line Numbers
  1. // ==UserScript==
  2. // @name           iGoogle Suggest
  3. // @namespace      Devin Samarin
  4. // @description    This automatcally selects the top result for your query.
  5. // @include        *google.com/ig*
  6. // ==/UserScript==
  7. function makeRequest() {
  8.     GM_xmlhttpRequest({
  9.         method: 'GET',
  10.         url: 'http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&qu='+encodeURI(document.getElementById('q').value),
  11.         headers: {
  12.             'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3',
  13.         },
  14.         onload: function(responseDetails) {
  15.  
  16.             var response = responseDetails.responseText;
  17.             document.getElementById('q').value = response.split('["')[2].split('"')[0];
  18.         }
  19.     });
  20. }
  21. var quer = document.getElementById('q');
  22. quer.onkeydown = "alert('asa');";
onKeyDown = function() { ... };

onkeydown = function() { ... };

onkeydown = "...";

onKeyDown = "...";

onKeyDown = makeRequest;

onkeydown = makeRequest;
Jul 11 '07 #1
1 5551
gits
5,390 Expert Mod 4TB
hi ...

add the onkeydown-eventhandling into a call from the onload-handler of the documents body ... during load the page is not fully rendered and the node is not available to be retrieved ... when you try it onload ... then the entire dom is loaded and document.getElementById finds your node and it will work then ;)

kind regards
Jul 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by joebob | last post: by
22 posts views Thread by Mark Reginald James | last post: by
3 posts views Thread by Dunc | last post: by
6 posts views Thread by Alejandro Penate-Diaz | last post: by
2 posts views Thread by rockdale | last post: by
reply views Thread by =?Utf-8?B?QWJoaQ==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.