BlogLimit character textarea using Jquery

Limit character textarea using Jquery

-

Here we can do, copy this jquery plugins :

jQuery.fn.maxLength = function(max){
this.each(function(){
//Get the type of the matched element
var type = this.tagName.toLowerCase();
//If the type property exists, save it in lower case
var inputType = this.type? this.type.toLowerCase() : null;
//Check if is a input type=text OR type=password
if(type == “input” && inputType == “text” || inputType == “password”){
//Apply the standard maxLength
this.maxLength = max;
}
//Check if the element is a textarea
else if(type == “textarea”){
//Add the key press event
this.onkeypress = function(e){
//Get the event object (for IE)
var ob = e || event;
//Get the code of key pressed
var keyCode = ob.keyCode;
//Check if it has a selected text
var hasSelection = document.selection? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd;
//return false if can’t write more
return !(this.value.length >= max && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection);
};
//Add the key up event
this.onkeyup = function(){
//If the keypress fail and allow write more text that required, this event will remove it
if(this.value.length > max){
this.value = this.value.substring(0,max);
}
};
}
});
};

For execute , put on head (but not on your head ):

<script type=”text/javascript”>

$().ready(function(){

$(“#leasure_narrative”).maxLength(300);

});

</script>

Ardhitya Wiedha Irawan
Ardhitya Wiedha Irawanhttp://aiueo.web.id
Full time Web Developer - Part time Android Coder - Part time Publisher - Big fan of #GGMU.

3 COMMENTS

  1. 🙂 MAS Ardhit… klo bisa kasih link contoh juga dunk…. biar bisa liat juga hasilnya.

    Numpang Cop Pas yah 🙂

    Chayoooo Smangat Mas ^_^

  2. I see a lot of interesting articles on your blog. You have to spend a lot of time writing, i
    know how to save you a lot of work, there is a tool that creates unique, SEO friendly articles in couple of minutes,
    just type in google – laranita’s free content source

Comments are closed.

Latest news

Perbedaan Apache2 Reload dan Restart ?

Kamu pengguna apache ? ahh selamat! berarti kamu orang lama yang sulit move on haha. Konon sekarang di dunia...

Membuat Shortcut untuk switch Dark dan Light Mode di Macbook

Baru baru ini aku menginginkan sebuah fungsi tombol yang bisa mengganti tema di Macbook secara cepat, dari Dark Mode...

Cara buat Sticker langsung di Web WhatsApp tanpa Install aplikasi!

Hai sob! kali ini gulangguling.com akan berbagi cara mudah membuat sticker untuk whatsapp tanpa harus install aplikasi lainnya. Sering...

Cara Mengembalikan Nomer WhatsApp yang terkena Banned

Halo teman-teman. Kali ini saya akan berbagi cara mengembalikan nomer yang sudah terkena banned dari aplikasi WhatsApp. Tapi sebelumnya...

Aplikasi Rambox, dapat digunakan untuk login banyak akun WhatsApp hingga marketing jualan.

Aplikasi Rambox adalah sebuah program yang dirancang untuk mengintegrasikan beberapa aplikasi chatting dan kolaborasi dalam satu tempat. Dengan menggunakan...

Cara melihat history Kometar dan Like di Instagram

Pernah penasaran dengan apa saja sih yang pernah kita lakukan di Instagram? seperti kita likes komentarin postingan siapa saja...

Must read

You might also likeRELATED
Recommended to you