Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old November 19th, 2007, 12:47 PM   #1
New Member
 

Join Date: Nov 2007
Location: Oregon
Age: 46
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 tejaxx is on a distinguished road
[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 Code:
<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; November 19th, 2007 at 12:48 PM.. Reason: Please use vBcode when pasting code in your post ;)
tejaxx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 19th, 2007, 12:52 PM   #2
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: Change Input Textbox Background Color

Maybe add onkeypress="ChkCb()"
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 19th, 2007, 12:56 PM   #3
Reputable Member
 

Join Date: Apr 2007
Location: Scotland
Age: 19
Posts: 236
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Blake121 will become famous soon enough
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?
Blake121 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 19th, 2007, 04:12 PM   #4
New Member
 

Join Date: Nov 2007
Location: Oregon
Age: 46
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 tejaxx is on a distinguished road
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.
tejaxx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 19th, 2007, 04:16 PM   #5
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: Change Input Textbox Background Color

This is solved tehn? if you could mark it as solved via thread tools that would be great
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
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

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
[SOLVED] Change div background on hover of another element Aso JavaScript 11 March 10th, 2010 01:19 PM
Change Background colour based on input smudge618 JavaScript 2 February 6th, 2008 07:55 AM
Input textbox background trouble sanstepsan Your Design and Layout 1 February 17th, 2007 05:27 PM
A way to change background color of a menu list gohankid77 HTML, XHTML and CSS 1 October 12th, 2004 06:14 AM
Anybody know how to change the color of a text input form in Physt HTML, XHTML and CSS 7 August 16th, 2004 04:44 AM


Search Engine Optimization by vBSEO 3.2.0 RC8