Help. While there was no function to check the number of characters (without spaces), everything went like clockwork.

ltrim is not defined = (

And does not unlock the 2 element (name).

function trim(str, chars) { var nam = ltrim(rtrim(str, chars), chars); return nam.length; } function cmena(a){ if (trim(a.value) > 1) { document.imy.name.disabled = 0; } else { document.imy.ok.disabled = 1; } } function cmena_2(a) { if (trim(a.value) >2) { document.imy.ctil['0'].disabled = 0;document.imy.ctil['1'].disabled = 0; document.imy.ctil['3'].disabled = 0;document.imy.ctil['2'].disabled = 0; } else { document.imy.ok.disabled = 1; } } function cmena_3(a) { if (a.checked) { document.imy.opis.disabled = 0; } else { document.imy.ok.disabled = 1; } } function cmena_4(a) { if (trim(a.value) >10 && trim(document.imy.name.value) > 2 && trim(document.imy.avtor.value) >1) { document.imy.ok.disabled = 0; } else { document.imy.ok.disabled = 1; } } 
  • @Ivan Use the 101010 button to format the code. - Nicolas Chabanovsky

3 answers 3

The rights interpreter - ltrim does not exist :) Use this implementation of the trim function:

 function trim( str, charlist ) { charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1'); var re = new RegExp('^[' + charlist + ']+|[' + charlist + ']+$', 'g'); return str.replace(re, ''); } 
  • Alex Silaev. And your code will remove all spaces? I just need only at the beginning and end) Thank you. - Ivan
  • Thank!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - Ivan
  • The trim function always cut off various spaces only at the beginning and at the end :) ps: this is not my function, but a very popular implementation from Kevin van Zonneveld :) - Alex Silaev

Or from php.js >>>

    Why can't the trim method of string be used?

     <html> <Head> <meta http-equiv="Content-Type" content="text/html; charset=cp1251"/> <title>trim() test</title> <script> alert('|'+' \n\u0009 abb '.trim()+'|'); </script> </head> <body> </body> </html>