Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 3rd, 2004, 06:49 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
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.
Reply With Quote
  #2 (permalink)  
Old July 3rd, 2004, 08:36 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
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
Reply With Quote
  #3 (permalink)  
Old July 3rd, 2004, 08:40 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old July 3rd, 2004, 08:46 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
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

Reply With Quote
  #5 (permalink)  
Old July 3rd, 2004, 08:57 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
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

<><
Reply With Quote
  #6 (permalink)  
Old July 3rd, 2004, 09:05 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
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

Reply With Quote
  #7 (permalink)  
Old July 3rd, 2004, 10:44 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
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

Reply With Quote
  #8 (permalink)  
Old July 4th, 2004, 04:07 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
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
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
  #9 (permalink)  
Old July 4th, 2004, 09:31 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:57 AM.


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