Javascript กำหนดจำนวนตัวอักษร(Maxlength)ให้กับ Textarea

สำหรับใครที่ต้องการกำหนดจำนวนตัวอักษรของ text area ให้เหมือน text input นั้นลอง script ตัวนี้เลยครับ support ทั้ง ie และ firefox
Javascript

function ismaxlength(obj){

var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""

if (obj.getAttribute && obj.value.length>mlength)

obj.value=obj.value.substring(0,mlength)

}

ตัวอย่าง

<textarea maxlength="40" onkeyup="return ismaxlength(this)"></textarea>

ที่มา: http://www.dynamicdrive.com/dynamicindex16/maxlength.htm

You can leave a response, or trackback from your own site. Responses are currently closed, but you can trackback from your own site. You can skip to the end and leave a response. Pinging is currently not allowed. Both comments and pings are currently closed.
Powered by WordPress | Shop Free T-Mobile Phones Online | Thanks to Verizon Phones without Contract, MMORPG Games and Sell Car