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
| 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 30th, 2003, 10:06 PM
Authorized User
Join Date: Jun 2003
Location: Quezon City, NCR, Philippines.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default change background color of inputbox

hi again to all and good day.

is there anyone can help me how to code in javascript for changing the background color of inputbox.

let say i have 2 checkbox a YES and NO. if the user check NO. then my inputbox fields will change the background color so it will distinguish as disabled fields. can you give me some sample codes?

thanks in advance..

Reply With Quote
  #2 (permalink)  
Old July 1st, 2003, 03:14 AM
Friend of Wrox
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

The syntax you need to change the background colour is:
object.style.backgroundColor = New_Color

here's a simple example for you:
<script type="text/javascript" language="javascript">
function changeColour()
  if (document.frmSurvey.fld2.checked)
    document.frmSurvey.fld1.style.backgroundColor="#FF0000"; // red
    document.frmSurvey.fld1.style.backgroundColor="#FFFFFF"; // white
<form name="frmSurvey" id="frmSurvey">
<input type="text" name="fld1" id="fld1"><br>
<input type="checkbox" name="fld2" id="fld2" onclick="changeColour()">change colour<br>
Reply With Quote
  #3 (permalink)  
Old July 1st, 2003, 09:36 AM
Authorized User
Join Date: Jun 2003
Location: Lexington, KY, USA.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post

If you want a standard color and you know its name, you can also use


There are many named colors that will work.


(Old dog learning new tricks...)
Reply With Quote
  #4 (permalink)  
Old December 1st, 2009, 02:22 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default use jQuery to build your own inputBox


You can perform it using jQuery. Are you familiar with jQuery?
It is a javascript library that enables you to any visual tasks like dragging windows, made any picture rounded, etc.
for example notice following:
$("div > p").css("background","#0C0C0C");
this means that change "background" propery of every "p" tag that is nested into a "div" tag, to "#0C0C0C".

I put some files in my blog for you. by these you can learn to perform what you wanted and other things.





jquery.js in main javascript library. you can even get a link from Google servers.
Reply With Quote

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
Change background color using CSS pigtail Javascript How-To 9 April 4th, 2010 11:13 AM
change color of background meena88 C# 2005 3 December 1st, 2009 04:48 AM
Change the background color of a msgbox nobreferreira VB.NET 2002/2003 Basics 3 October 28th, 2004 09:37 AM
change background color of cell based on value vurtman ASP.NET 1.0 and 1.1 Basics 4 February 26th, 2004 03:52 PM

All times are GMT -4. The time now is 10:01 PM.

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