Want to put character limit on a variable on a catalog item
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2022 12:05 PM
Hi - i have a variable on a catalog item that is a singe line text field.
I want to do a onSubmit catalog client script so that users can't put more than 15 characters in the field. I have attempted w/ the script below and am unable to have it work successfully. If someone could please correct my script.
function onSubmit() {
var length = 15;
var name = g_form.getValue('hostname');
if(name.length > length)
alert('Please ensure the hostname is not more than 15 characters') ;
}
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2025 03:09 AM
Try this one.
var hostName = g_form.getValue("u_host_ip");
hostName = hostName.split('');
var len = hostName.length;
alert(len);
if (len > 15) {
g_form.showFieldMsg('u_host_ip', "Enter less than 15 characters", 'error');
g_form.setValue('u_host_ip', hostName.substring(0, 15));
}
else{
g_form.hideFieldMsg('u_host_ip');
}