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 November 24th, 2005, 10:06 PM
Registered User
 
Join Date: Nov 2005
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..

 
Old November 25th, 2005, 05:44 AM
Friend of Wrox
 
Join Date: Jul 2003
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

 
Old November 25th, 2005, 06:18 AM
Friend of Wrox
 
Join Date: Jan 2005
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
 
Old November 25th, 2005, 01:35 PM
Registered User
 
Join Date: Nov 2005
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


 
Old November 25th, 2005, 01:39 PM
Registered User
 
Join Date: Nov 2005
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

 
Old November 28th, 2005, 06:06 AM
Friend of Wrox
 
Join Date: Jul 2003
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






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





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