Skip Navigation

[Resolved] Limited Characters in a Textfield and 2 textareas in 1 form

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2618989

Tell us what you are trying to do?
Limited Characters in a Textfield and 2 textareas in 1 form

If I use only the textareas then its workd fine, but with the textfield it does not.

Is there any documentation that you are following?

(function($) {
$.fn.extend( {
limiter: function(limit, elem) {
$(this).on("keyup focus", function() {
setCount(this, elem);
});
function setCount(src, elem) {
var chars = src.value.length;
if (chars > limit) {
src.value = src.value.substr(0, limit);
chars = limit;
}
elem.html( limit - chars );
}
setCount($(this)[0], elem);
}
});
})(jQuery);

var elem = jQuery("#chars0");
jQuery("textfield[name='post_title']").limiter(10, elem);

var elem1 = jQuery("#chars1");
jQuery("textarea[name='wpcf-korte-omschrijving']").limiter(100, elem1);

var elem2 = jQuery("#chars2");
jQuery("textarea[name='wpcf-omschrijving-project']").limiter(2000, elem2);

<div class="form-group col-md-12">
<label for="%%FORM_ID%%_post_title">[cred_i18n name='post_title-label']Project titel[/cred_i18n]</label>
[cred_field field='post_title' class='form-control' output='bootstrap']
<div>Aantal karakters over: <span id="chars0">10</span></div>

<div class="form-group col-md-12">
<label for="%%FORM_ID%%_korte-omschrijving">[cred_i18n name='korte-omschrijving-label']Korte omschrijving project[/cred_i18n]</label>
[cred_field field='korte-omschrijving' force_type='field' class='form-control' output='bootstrap']
<div>Aantal karakters over: <span id="chars1">100</span></div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label for="%%FORM_ID%%_omschrijving-project">[cred_i18n name='omschrijving-project-label']Omschrijving project[/cred_i18n]</label>
[cred_field field='omschrijving-project' force_type='field' class='form-control' output='bootstrap']
<div>Aantal karakters over: <span id="chars2">2000</span></div>
</div>

This is the form i'm working on
hidden link

What is the link to your site?
hidden link

#2619269

Hi,

Thank you for contacting us and I'd be happy to assist.

For the post title (text field), you'll need to change the following line, from:


jQuery("textfield[name='post_title']").limiter(10, elem);

To:


jQuery("input[name='post_title']").limiter(10, elem);

This should do the trick.

regards,
Waqar

#2619383

My issue is resolved now. Thank you!