Can any one tell me,what are the equivalent functions in Javascript for trim,rtrim ,and ltrim.
Printable View
Can any one tell me,what are the equivalent functions in Javascript for trim,rtrim ,and ltrim.
There's no JavaScript trim() function as such. This should suit your needs though....
The script came from here: http://developer.irt.org/script/1310.htmCode:<script language="JavaScript">
<!--
function trim(strText) {
// this will get rid of leading spaces
while (strText.substring(0,1) == ' ')
strText = strText.substring(1, strText.length);
// this will get rid of trailing spaces
while (strText.substring(strText.length-1,strText.length) == ' ')
strText = strText.substring(0, strText.length-1);
return strText;
}
//--></script>
Hi, using the above trim function why is this not working ?
How do I use that trim function ?Code:<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function ValidateForm(form)
{
//This line works
alert ('*' + form.txtCourriel.value);
// This line does not work
alert ('*' + trim(form.txtCourriel.value));
// This line does not work
alert ('*' + trim(form.txtCourriel));
}
</SCRIPT>
Jeeze that's an old thread!
This is correct and it works fine for me.Code:
alert ('*' + trim(form.txtCourriel.value));