Want to put character limit on a variable on a catalog item

Charles Hong
Mega Expert

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

PS930585
Tera Contributor

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');
    }