Zoeken in Support

Vermijd ondersteuningsscams. We zullen u nooit vragen een telefoonnummer te bellen, er een sms naar te sturen of persoonlijke gegevens te delen. Meld verdachte activiteit met de optie ‘Misbruik melden’.

Learn More

Deze conversatie is gearchiveerd. Stel een nieuwe vraag als u hulp nodig hebt.

mozilla browser not supporting kep up event properly

  • 7 antwoorden
  • 1 heeft dit probleem
  • 14 weergaven
  • Laatste antwoord van taj

more options

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>

Gekozen oplossing

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

Dit antwoord in context lezen 👍 1

Alle antwoorden (7)

more options

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:

more options

on console I am getting error like

ReferenceError: event is not defined.

but same is working fine on IE & Chrome.

more options

See my earlier reply for compatibility information.

more options

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

more options

Gekozen oplossing

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

Bewerkt door jscher2000 - Support Volunteer op

more options

thanks dear Sir "jscher2000"

more options

tajk said

thanks dear Sir "jscher2000"

now its working fine on all browsers.