Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
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 June 30th, 2003, 10:06 PM
Authorized User
 
Join Date: Jun 2003
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..




Mabuhay!!!
__________________
Mabuhay!!!
 
Old July 1st, 2003, 03:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

here's a simple example for you:
Code:
<html>
<head>
<script type="text/javascript" language="javascript">
function changeColour()
{
  if (document.frmSurvey.fld2.checked)
  {
    document.frmSurvey.fld1.style.backgroundColor="#FF0000"; // red
  }
  else
  {
    document.frmSurvey.fld1.style.backgroundColor="#FFFFFF"; // white
  }
}
</script>
</head>
<body>
<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>
</body>
</html>
 
Old July 1st, 2003, 09:36 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

....backgroundColor="red";

There are many named colors that will work.

-Van

-Van
(Old dog learning new tricks...)
 
Old December 1st, 2009, 02:22 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default use jQuery to build your own inputBox

--------------------------------------------------------------------------------

Hello,
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.

http://aspnet35.brinkster.net/beetle...i-20090115.chm

http://aspnet35.brinkster.net/beetle...ery-1.2-v1.chm

http://aspnet35.brinkster.net/beetle_jaipur/jquery.js

http://aspnet35.brinkster.net/beetle...uery.corner.js

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





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





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