|
-
Mar 15th, 2001, 11:25 AM
#1
Thread Starter
Lively Member
Can any one tell me,what are the equivalent functions in Javascript for trim,rtrim ,and ltrim.
-
Mar 16th, 2001, 02:01 AM
#2
Frenzied Member
There's no JavaScript trim() function as such. This should suit your needs though....
Code:
<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>
The script came from here: http://developer.irt.org/script/1310.htm
-
Dec 8th, 2005, 03:56 PM
#3
Hyperactive Member
Re: Javascript-Trim functions
Hi, using the above trim function why is this not working ?
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>
How do I use that trim function ?
-
Dec 9th, 2005, 04:08 AM
#4
Addicted Member
Re: Javascript-Trim functions
Jeeze that's an old thread!
Code:
alert ('*' + trim(form.txtCourriel.value));
This is correct and it works fine for me.
Another light-hearted post from Guru 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|