[SOLVED] Change Input Textbox Background Color

This is a discussion on "[SOLVED] Change Input Textbox Background Color" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Change Input Textbox Background Color are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 19th, 2007, 16:47
New Member
Join Date: Nov 2007
Location: Oregon
Age: 44
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Change Input Textbox Background Color

I have a web page with a checkbox and a textbox. When I check/uncheck the checkbox, I want to disable/enable the textbox and change the textbox background color.

I am using the code below. It works except the color change is not apparent until I physically click on the textbox. Can I make the color change happen immediatly when I change the checkbox?
HTML: Select all
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<SCRIPT LANGUAGE = "JAVASCRIPT">
<!--
function ChkCb() {
if( MyForm.IDcb.checked ) {
MyForm.IDtx.style.backgroundColor = "#D4D2D2";
MyForm.IDtx.style.color="#D4D2D2"
MyForm.IDtx.disabled = true;
} else {
MyForm.IDtx.style.backgroundColor = "#FBFBFB";
MyForm.IDtx.style.color="#000000"
MyForm.IDtx.disabled = false;
}
}
//-->
</script>
</head>
<body>
<form method="POST" name="MyForm" action="myscript.cgi">
Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><input type="checkbox" name="cb" id="IDcb" value="ON" onchange=ChkCb() ></p>
<p><input type="text" name="tx" size="20" id="IDtx"></p>
<p><input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>

Last edited by karinne; Nov 19th, 2007 at 16:48. Reason: Please use vBcode when pasting code in your post ;)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 19th, 2007, 16:52
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Change Input Textbox Background Color

Maybe add onkeypress="ChkCb()"
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 19th, 2007, 16:56
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Change Input Textbox Background Color

Got a link to the page in question?

Would really help.

And why is this " Format="TEXT/CSV" S-Label-Fields="TRUE" --> " sitting randomly in the middle of the page? Maybe take that out?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 19th, 2007, 20:12
New Member
Join Date: Nov 2007
Location: Oregon
Age: 44
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Change Input Textbox Background Color

And why is this " Format="TEXT/CSV" S-Label-Fields="TRUE" --> " sitting randomly in the middle ...

I deleted some comments when I pasted the code to this forum; I apparently missed the tail end of this comment. This was not the problem.

Maybe add onkeypress="ChkCb()"

Onkeypress does not seem to work either; but, this did work:

Split the disabling and the color change into two functions. Use the checkbox onchange event to disable/enable the textbox, and use the forms onkeyup and onmouseup events to change the textbox color.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 19th, 2007, 20:16
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Change Input Textbox Background Color

This is solved tehn? if you could mark it as solved via thread tools that would be great
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Background colour based on input smudge618 JavaScript Forum 2 Feb 6th, 2008 11:55
[SOLVED] Change div background on hover of another element Aso JavaScript Forum 10 Dec 8th, 2007 11:08
Input textbox background trouble sanstepsan Starting Out 1 Feb 17th, 2007 21:27
A way to change background color of a menu list gohankid77 Web Page Design 1 Oct 12th, 2004 10:14
Anybody know how to change the color of a text input form in Physt Web Page Design 7 Aug 16th, 2004 08:44


All times are GMT. The time now is 05:53.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42