Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2004, 06:49 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default toLowerCase() Method

Argh!

Ripping my hair out here cos I can't get the syntax right! What I need is this. The user enters some text into a <textarea> and clicks a button which in turn calls my function. My script to convert it to lower case using toLowerCase() (surprise surprise). I then continue making my string comparisons! Help!!!!!!

cheers
interrupt

__________________
\'sync\' &lt;cr&gt;
The name specified is not recognized as an internal or external command, operable program or batch file.
 
Old July 3rd, 2004, 08:36 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

function test()
{
    var S = new String(document.form1.textarea_name.value);
    alert(S.toLowerCase());
}
Hope this helps..

Om Prakash
 
Old July 3rd, 2004, 08:40 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Om,

Thanks for the suggestion. But i found another way of doing this.

var myStr2 = document.form1.text1.value.toLowerCase()

I was looking for a way of doing the comparison in the background, and this seems to fit.

Thanks again!
interrupt

 
Old July 3rd, 2004, 08:46 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually,

Can you include an Or || clause in an indexOf() method statement?

So what I need to say is something like this:

var s =document.form1.text1.value

s.indexOf("text1\'s value" || "text2\'s value")

interrupt

 
Old July 3rd, 2004, 08:57 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

There's two ways that I can think of to do this. You could use regular expressions or you could do this:

if(s.indexOf("whatever")||s.indexOf("something"))
{
    //code here
}

HTH,

Snib

<><
 
Old July 3rd, 2004, 09:05 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Once again Snib, nice one! One more quick one for ya, I need to find a way of eliminating nasty old punctuation from the users input at the comparison stage. Any ideas?

Thanks
interrupt

 
Old July 3rd, 2004, 10:44 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, now something strange is going on. When I use that code, the code inside the braces executes no matter what the indexOf method returns. Here is the affected code:

var myStr3 = document.form2.text2.value.toLowerCase()

var count2 = 0

if(myStr3.indexOf("one")||myStr3.indexOf("on"))
{
alert(myStr3)
count2 = count2 + 1
}

interrupt

 
Old July 4th, 2004, 04:07 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Is this for presentation or are you pre-processing for the server?

If for presentation CSS is better suited.

textarea {
    text-transform: lowercase;
}

Personally, I'd use CSS on the client-side and process the data according to how I want it on the server-side, but that's just me ;).

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old July 4th, 2004, 09:31 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Richard,

All the processing will be done on the client in the background as I only have access to a File and Print server this year (budget sucks don't it? lol). It's basically going to be an exam and I need some fairly fine tuned string comparisons going on when the user hits the Grade Me button. I need to look back along the 30 questions and grade each one individually before tallying each score into a total and giving a percentage, before telling the user which areas they need to study (ie the questions they got wrong). Alot of the script is heavily dependant on the indexOf() function. I'm also thinking about using RegExps as well but as I've only been using Javascript for about 3 months now, it seems a bit daunting! If you have any suggestions to make my life that bit easier, it's always welcome!

Thanks
interrupt






Similar Threads
Thread Thread Starter Forum Replies Last Post
About Method VeradisSanthanam ASP.NET 2.0 Basics 1 June 19th, 2007 06:52 AM
method amit_p_patel VB How-To 2 May 25th, 2007 01:46 AM
Why is this method placed in filip BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 August 25th, 2006 09:40 PM
Best method rastham SQL Server 2000 2 February 16th, 2006 12:59 AM
Method StanArtis BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 December 6th, 2004 06:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.