X
Tocca qui per la versione per piattaforma mobile del sito.

Forum di supporto

Questa discussione è archiviata. Inserire una nuova richiesta se occorre aiuto.

mozilla browser not supporting kep up event properly

taj
Inserita

please check attachment

used code here, onkeypress = "return taLimit(250)", onkeyup = "return taCount(spcl,250)"


<script language="javascript">

   function taLimit(maxLength) {
       var taObj = event.srcElement;
       if (taObj.value.length === maxLength * 1) return false;
   }
   function taCount(visCnt, maxLength) {
       var taObj = event.srcElement;
       if (taObj.value.length > maxLength * 1) taObj.value = taObj.value.substring(0, maxLength * 1);
       if (visCnt) visCnt.innerText = maxLength - taObj.value.length;
   }

</script>

please check attachment used code here, onkeypress = "return taLimit(250)", onkeyup = "return taCount(spcl,250)" <script language="javascript"> function taLimit(maxLength) { var taObj = event.srcElement; if (taObj.value.length === maxLength * 1) return false; } function taCount(visCnt, maxLength) { var taObj = event.srcElement; if (taObj.value.length > maxLength * 1) taObj.value = taObj.value.substring(0, maxLength * 1); if (visCnt) visCnt.innerText = maxLength - taObj.value.length; } </script>

Soluzione scelta

Try passing a reference to the textarea element to the function using this:

<textarea onkeypress="return taLimit(250, this)" onkeyup="return taCount(spcl, 250, this)"></textarea>

<script> function taLimit(maxLength, taObj) {   if (taObj.value.length === maxLength * 1) return false; } function taCount(visCnt, maxLength, taObj) {   if (taObj.value.length > maxLength * 1) taObj.value = taObj.value.substring(0, maxLength * 1);   if (visCnt) visCnt.innerText = maxLength - taObj.value.length; } </script>

The this keyword is a little tricky. I'm suggesting the approach listed under the heading Combination toward the end of this article: https://www.quirksmode.org/js/this.html

Leggere questa risposta nel contesto 1

Dettagli aggiuntivi sul sistema

Applicazione

  • User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0

Ulteriori informazioni

jscher2000
  • Top 10 Contributor
8794 soluzioni 71950 risposte

Does the console show any script errors?

You can set up demo pages on https://jsfiddle.net/ or https://codepen.io/ for interactive use.

Please note the compatibility sections of the following articles and consider supporting the Extended Support Release of Firefox 60 as well as the release version Firefox 63:

Does the console show any script errors? * For the current tab: https://developer.mozilla.org/docs/Tools/Web_Console * Global: https://developer.mozilla.org/docs/Tools/Browser_Console You can set up demo pages on https://jsfiddle.net/ or https://codepen.io/ for interactive use. Please note the compatibility sections of the following articles and consider supporting the Extended Support Release of Firefox 60 as well as the release version Firefox 63: * https://developer.mozilla.org/docs/Web/API/Window/event * https://developer.mozilla.org/docs/Web/API/Event/srcElement

Risposta utile

on console I am getting error like

ReferenceError: event is not defined.

but same is working fine on IE & Chrome.

on console I am getting error like ReferenceError: event is not defined. but same is working fine on IE & Chrome.
jscher2000
  • Top 10 Contributor
8794 soluzioni 71950 risposte

Risposta utile

See my earlier reply for compatibility information.

See my earlier reply for compatibility information.

Utente che ha posto la domanda

I have already used "event.srcElement" but that is not supporting by mozilla is there any other solution?

I have already used "event.srcElement" but that is not supporting by mozilla is there any other solution?
jscher2000
  • Top 10 Contributor
8794 soluzioni 71950 risposte

Soluzione scelta

Try passing a reference to the textarea element to the function using this:

<textarea onkeypress="return taLimit(250, this)" onkeyup="return taCount(spcl, 250, this)"></textarea>

<script> function taLimit(maxLength, taObj) {   if (taObj.value.length === maxLength * 1) return false; } function taCount(visCnt, maxLength, taObj) {   if (taObj.value.length > maxLength * 1) taObj.value = taObj.value.substring(0, maxLength * 1);   if (visCnt) visCnt.innerText = maxLength - taObj.value.length; } </script>

The this keyword is a little tricky. I'm suggesting the approach listed under the heading Combination toward the end of this article: https://www.quirksmode.org/js/this.html

Try passing a reference to the textarea element to the function using '''this''': &lt;textarea onkeypress="return taLimit(250, '''this''')" onkeyup="return taCount(spcl, 250, '''this''')">&lt;/textarea> &lt;script> function taLimit(maxLength, '''taObj''') { &nbsp;&nbsp;if (taObj.value.length === maxLength * 1) return false; } function taCount(visCnt, maxLength, '''taObj''') { &nbsp;&nbsp;if (taObj.value.length > maxLength * 1) taObj.value = taObj.value.substring(0, maxLength * 1); &nbsp;&nbsp;if (visCnt) visCnt.innerText = maxLength - taObj.value.length; } &lt;/script> The '''this''' keyword is a little tricky. I'm suggesting the approach listed under the heading '''Combination''' toward the end of this article: https://www.quirksmode.org/js/this.html

Modificato da jscher2000 il

Utente che ha posto la domanda

thanks dear Sir "jscher2000"

thanks dear Sir "jscher2000"

Utente che ha posto la domanda

tajk said

thanks dear Sir "jscher2000"

now its working fine on all browsers.

''tajk [[#answer-1168868|said]]'' <blockquote> thanks dear Sir "jscher2000" </blockquote> now its working fine on all browsers.