Javascript dynamically change onkeydown event?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eboyjr14
    New Member
    • Apr 2007
    • 27

    Javascript dynamically change onkeydown event?

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


    [CODE=javascript]// ==UserScript==
    // @name iGoogle Suggest
    // @namespace Devin Samarin
    // @description This automatcally selects the top result for your query.
    // @include *google.com/ig*
    // ==/UserScript==
    function makeRequest() {
    GM_xmlhttpReque st({
    method: 'GET',
    url: 'http://suggestqueries. google.com/complete/search?output=f irefox&client=f irefox&qu='+enc odeURI(document .getElementById ('q').value),
    headers: {
    'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3',
    },
    onload: function(respon seDetails) {

    var response = responseDetails .responseText;
    document.getEle mentById('q').v alue = response.split( '["')[2].split('"')[0];
    }
    });
    }
    var quer = document.getEle mentById('q');
    quer.onkeydown = "alert('asa');" ;[/CODE]

    onKeyDown = function() { ... };

    onkeydown = function() { ... };

    onkeydown = "...";

    onKeyDown = "...";

    onKeyDown = makeRequest;

    onkeydown = makeRequest;
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    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.getEle mentById finds your node and it will work then ;)

    kind regards

    Comment

    Working...