Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim does not work! 1

Status
Not open for further replies.

alexfrumkin

Programmer
Mar 27, 2000
4
0
0
US
&lt;script language=&quot;JavaScript&quot;&gt;<br>function check(passForm){<br><br>if (RTrim(LTrim(frmLog.UserName.value))==&quot;&quot;){<br> alert('Name cannot be left Blank');<br> return false<br>}<br> <br>if&nbsp;&nbsp;(frmLog.Password.value==&quot;&quot;){<br> alert (&quot;Password canot be left blank&quot;)<br> return false<br>}<br>return true<br>}<br>&lt;/script&gt;<br><br><b>and that does not work!I was advised to use this rtrim/ltrim and it gives me &quot;object expected&quot; error. I am very new to Javascript, so I am lost. All I need to do is to check for spaces that user entered instead of password, or name. In VB it is simply Trim(str). PLEASE, HELP!<br><br>Thank you very much for your time and effort.<br></b>
 
You didn't post the code that calls the check() function, <br>so I can't see how you're calling the function, but right off I can see that the check&nbsp;&nbsp;function accepts a form as a parameter but you don't use it.&nbsp;&nbsp;If you want to hardcode the form name in the functions and not use the passForm parameter,&nbsp;&nbsp;try changing the way you reference the fields on the form to smething like this:<br><br>document.forms[&quot;frmLog&quot;].UserName.Value<br><br>if you want to use the passForm parameter(assuming you're passing it correctly), use<br><br>passForm.UserName.value<br> <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
&lt;form name=&quot;frmLog&quot; method=&quot;post&quot; action=&quot;frmLogIn.asp&quot; onsubmit=&quot;return check(this)&quot;&gt;<br><br>this it how I pass the parameter. It works in every case, except when I try to do that &quot;trim&quot; thing. So, that means that the parameter gets passed OK, but it chokes on the Trim...I am confused...<br><br>Thank you very much for your time and effort (and for putting up with me)
 
alex,<br>&nbsp;&nbsp;&nbsp;As I mentioned above, you're not using the reference to the form that you're passing in.<br>&nbsp;&nbsp;&nbsp;your code worked fine for me (in IE5) after I changed your calls to the trim functions to use 'passForm' instead of 'frmLog' to reference the form.<br><br>for example:<br>RTrim(LTrim(passForm.UserName.value))<br><br> <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
I didn't even know that trim was a function in JavaScript (I get the feeling it's an IE only feature).&nbsp;&nbsp;Check out my answer in your other post. <p>REH<br><a href=mailto:hawkdogg@crosswinds.net>hawkdogg@crosswinds.net</a><br><a href= by Linux</a><br>Learn Linux and Leave out the Windows :)
 
ndogg,<br>&nbsp;&nbsp;&nbsp;Trim is not a function in Javascript.&nbsp;&nbsp;He got the function from the 4guysfromrolla site.&nbsp;&nbsp;This was referenced in an earlier thread.&nbsp;&nbsp;Sorry for the confusion. <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top