client script to check string length and restrict user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2016 02:47 PM
Hi all,
we have a requirement to restrict user not to enter more than 100 characters for a field of type string. currently the field length is 120 but we don't want user to enter more than 100. For this i am thinking a "onChange" client script, i am not sure onChange is correct. Could you please guys help me how to write a clientscript to restrict the user by displaying an error beside the field to correct the length of the message he typed to 100 based on condition of assignedto=ABC,assignment group=XYZ.
Thanks,
Sry
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2016 02:54 PM
Hi Sry,
Sample script-Untested code. Adjust as per your req.
var assignedto = g_form.getDisplayBox('assigned_to').value;
var assignmengrp = g_form.getDisplayBox('assignment_group').value;
var field = g_form.getValue('short_description').length;
if(assignedto == 'XXX' && assignmengrp == 'XXX' && field>100)
{
alert('YOUR TEXT');
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2016 02:55 PM
Hi Sry,
If it is a field of type string the dictionary form has a field called Max Length where you can enter the number of characters. This is obviously different to the width of the field which could be larger.
If it is a variable of Single line text you can add a attribute called max_length
If either of the above doesnt fit your requirement, there is a blog post below which details a client script aiding in achieving the same.
Setting the Maximum Length for a String Variable