Hii
I am doing a project dealt with sending SMS ..
So i have to control the length of the message to be sent ..
But for textbox of Multiline type did not allowing the MaxLength property ..
Plz help me
Hii
I am doing a project dealt with sending SMS ..
So i have to control the length of the message to be sent ..
But for textbox of Multiline type did not allowing the MaxLength property ..
Plz help me
A practical, modern solution builds on ’s client-side idea but makes it robust for typing, pastes and older browsers: add the HTML5 maxlength as a progressive enhancement, use the input event for live enforcement and a remaining-character display, and always enforce the limit server-side before sending the SMS (client checks are convenience only). This addresses ’s need for a reliable length control for SMS.
Example (HTML + plain JavaScript):
<textarea id="message" maxlength="160" rows="5" cols="50"></textarea>
<div>Remaining: <span id="remaining">160</span></div>
<button id="send">Send</button> <script>
(function(){
var ta = document.getElementById('message');
var rem = document.getElementById('remaining');
var max = 160;
function update(){
if (ta.value.length > max) ta.value = ta.value.slice(0, max);
rem.textContent = max - ta.value.length;
}
ta.addEventListener('input', update, false); // handles typing and paste
update();
})();
</script> Server-side validation (example in C#) — enforce the same rule on the server to prevent bypass:
if (string.IsNullOrEmpty(message) || message.Length > 160)
{
// reject or return validation error before sending SMS
} Notes and troubleshooting:
onchange fires on blur; input gives immediate feedback and handles paste/IME. maxlength works in modern browsers but keep the JS fallback for older ones. Jump to Post— sedgey 58why not use a javascript function fired by the onchange event to check the length and prevent additonal entry if the length exceeds the max allowable
why not use a javascript function fired by the onchange event to check the length and prevent additonal entry if the length exceeds the max allowable
why not use a javascript function fired by the onchange event to check the length and prevent additonal entry if the length exceeds the max allowable
Thanks a lot Mr. sedgey
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.