This topic is locked

Limit Chars entered in text field 7.2?

7/20/2013 3:22:53 PM
ASPRunnerPro General questions
G
GerryT author

Below is the code from a post that Jane posted for 5.2 on limiting input in a text area field and a counter to display the amount of characters entered. Is there any updated code for 7.2?
Code entered in Edit ->Jacascript onload event. FieldName = your field

var ctrlFieldName = Runner.getControl(pageid, 'FieldName');

document.getElementById('counter').value = ctrlFieldName.getValue().length;

function func()

{

//update counter

document.getElementById('counter').value = ctrlFieldName.getValue().length;

//check if length of the entered value <40 characters

if (ctrlFieldName.getValue().length>40)

{

//show first 40 characters only

ctrlFieldName.setValue(ctrlFieldName.getValue().substr(0,40));

//update counter

document.getElementById('counter').value = 40;

}

}

ctrlFieldName.on('keyup', func);


Counter (entered after text field)

<input type=text value=0 id=counter disabled="disabled" size=3>
Sergey Kornilov admin 7/20/2013

It works in version 7.2 as well. This code is based on standard ASPRunnerPro Javascript API, should work in further versions as well.