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 November 24th, 2005, 10:06 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default COLOR CHANGE IN TEXTBOXES

Hi,

How do I change the text color in a textbox in a form?
first, I'm checking the value of a textbox, e.g
if(form.textbox1.value == "something")
{// change the text color to green }
else // change the text color to red

I'm using external javascript files that include the function that is validating the inputs in the textboxes...
Thanks, I appreciate it..

Reply With Quote
  #2 (permalink)  
Old November 25th, 2005, 05:44 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Rashad,

Try...
Code:
form.textbox1.style.color = form.textbox1.value == "something" ? "green" : "red";
HTH,

Chris

Reply With Quote
  #3 (permalink)  
Old November 25th, 2005, 06:18 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Rashad, when you are looking for styling code for javascript keep in mind MSDN Scirpting. Do a google, it gives you accurate descriptions.

www.crmpicco.co.uk
Reply With Quote
  #4 (permalink)  
Old November 25th, 2005, 01:35 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Chris,

Thanks alot, it worked perfect..
What if I want to display the value in a textbox with a 'bold' style in addition to the red or green color?

And what if I want to change the color of the textbox itself? Do I use the background property of the textbox??

Thanks again, that was really helpful..
Raha D


Reply With Quote
  #5 (permalink)  
Old November 25th, 2005, 01:39 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alright,
I just figured out changing the background color of a textbox?
But how do I change the text in a textbox to a "BOLD RED" or "BOLD GREEN"?

Thanks,
Rasha D

Reply With Quote
  #6 (permalink)  
Old November 28th, 2005, 06:06 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can manipulate other css properties the same way - style.fontWeight = "bold", style.backgroundColor = "red", etc...

Cheers,

Chris

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
textboxes or list boxes with multiple fore color svharishtech Pro VB 6 5 April 20th, 2007 05:04 PM
change cell color martin1 Visual Basic 2005 Basics 2 October 4th, 2006 08:55 AM
re: color change jack_in_black ASP.NET 2.0 Professional 0 July 11th, 2006 07:24 AM
change row color vivek_pon VS.NET 2002/2003 3 April 13th, 2006 01:42 PM
Using loop to change text of multiple textboxes snowy0 VB.NET 6 July 29th, 2004 08:54 AM



All times are GMT -4. The time now is 01:54 AM.


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