Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing event.which to verify if the user pressed the spacebar doesn't work in Firefox
    primarykey
    data
    text
    <p>I want a script to verify if the key pressed is 'spacebar', keycode 32. I noticed that IE uses other function names.</p> <p>I tried a lot of solutions found here and this:</p> <pre><code>event = event || window.event // IE does not pass event to the function if(event == window.event){ code = event.keyCode; }else{ code = event.which; } if(code == '32') {} </code></pre> <p>But it still didn't work in Firefox.</p> <p>I think I'm calling the function wrongly in Firefox. Look at the entire script:</p> <pre><code>&lt;textarea onkeydown="predicao(this);" cols="40" rows="10" id="test" onfocus="this.focus()"&gt;&lt;/textarea&gt; &lt;input id="example" style="display: none;" onkeydown="javascript: insert(this);"/&gt; &lt;script language="Javascript"&gt; &lt;!-- function predicao(objeto){ comprimento = objeto.value.length; var antipenultimo = comprimento - 4; var input = objeto.value.substring(antipenultimo,comprimento); var output = ""; for(i=0; i&lt;input.length; ++i){ if(output != "") output += ", "; output += input.charCodeAt(i); } if (output == "91, 91, 103, 32"){ var preditor = document.getElementById('example'); preditor.value = ''; preditor.style.display = 'block'; preditor.focus(); preditor.select(); } } function insert(objeto){ event = event.which || window.event // IE does not pass event to the function if(event == window.event){ code = event.keyCode; }else{ code = event.charCode; } if(keynum == '32') { var texto = document.getElementById('test').value; texto += objeto.value+']]'; $('#test').focus(); document.getElementById('test').value = texto; objeto.style.display = 'none'; } } $(document).ready(function(){ var data = "Ab Aco Ado Ala Mano Cata Ca Obo Olo Po Poq".split(" "); $("#example").autocomplete(data);}); &lt;/script&gt; </code></pre> <p>What I'm trying to do is - (I don't know the name) - a Prediction Help Inputter inside a textarea. It uses jQuery autocomplete. When the user types '[[g ' inside textarea (id=test), a input with autocomplete is opened (id=example), so it search in 'data'. When the user find the desired data, he must press spacebar to insert the data into the textarea, closing with ']]' But it doesn't work in Firefox.</p> <p>(And yes, I'm using JavaScript and jQuery to same elements in a totally wrong way because I'm not too good at this, I'll try to correct it after Firefox works.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload