April 27, 2024

MoDCore

Welcome to the core

Visual Countdown for open text field length

This will show you how to add a twitter like character count down on to any open question within your survey.
First off we want to enable the jquery library in your survey.
Survey themes, select the one you are using.
In the external Javascript URL paste this address into it
//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js

This script will add a visual element to the instruction area of a question.

If you paste this into the instruction field in designer.

<span class=”countdown”></span>
<script>

function updateCountdown() {
var remaining = 500 – $(‘textarea’).val().length;
if (remaining <= 0) {
var enteredText = $(‘textarea’).val().substr(0,500);
$(‘textarea’).val(enteredText);
$(‘.countdown’).addClass(‘errorquestion’);
} else {
$(‘.countdown’).removeClass(‘errorquestion’);
}
$(‘.countdown’).text(remaining + ‘ characters remaining.’);
}

$(document).ready(function() {
updateCountdown();
$(‘textarea’)
.change(updateCountdown)
.keyup(updateCountdown);
});
</script>

The numbers in bold is what you would change, don’t forget to set a field width as well.
Preview –

 

Copyright © All rights reserved. | Newsphere by AF themes.