0

Hi,

I have a textarea counter which has a limit of 160 characters. What I want to do is when the checkbox is ticked the character limit would charge to 140 characters. I have the following code:

Html:

<input type="checkbox" name="change" value="1" />
<textarea name="sms_text" id="sms_text" rows="8" cols="60" onKeyDown="limitText(this.form.sms_text,this.form.countdown,160);" onKeyUp="limitText(this.form.sms_text,this.form.countdown,160);"></textarea>
<br />
<font size="1">(Maximum characters: 160)<br />
You have <input readonly type="text" name="countdown" size="3" value="160" /> characters left.</font>

Javascript:

function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}

Is there any way I could do this? Can someone please help me? Thank you

2
Contributors
1
Reply
20
Views
4 Years
Discussion Span
Last Post by LastMitch
0

I have a textarea counter which has a limit of 160 characters. What I want to do is when the checkbox is ticked the character limit would charge to 140 characters. I have the following code:

@Annuscha

I never done that before. Change the limit of characters like that. I only implement the amount of characters that can be display but you are asking if it possible to display any amount of characters by checking a box?

In your code there should be a limited code that tells the javascript that the number of character is displayed.

The javascript code you provide is correct, it works.

You need to add few lines. What code have you add since?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.