DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   how do i change fore color in a textbox with javascript (http://www.daniweb.com/forums/thread43288.html)

sqlchopper Apr 13th, 2006 11:10 am
how do i change fore color in a textbox with javascript
 
I tried several things. i get invalid char or no object. can one change fore color or setup a mask. the text box contains numbers and if the number is negitive i need it to show in red, black if not.
var oRed = '#ff0000'
var oBlack = '#000000'
if (parseInt(document.getElementById('nm1TextBox').value) < parseInt(0))
{document.getElementById('nm1TextBox').forecolor = oRed;}
else
{document.getElementById('nm1TextBox').forecolor = oBlack;}

tgreer Apr 13th, 2006 12:47 pm
Re: how do i change fore color in a textbox with javascript
 
You need to access and modify the style collection.

document.getElementById("nm1Textbox").style.color = "red";

sqlchopper Apr 24th, 2006 9:50 am
Re: how do i change fore color in a textbox with javascript
 
thanks. i ended up changing the bgcolor. will try this in the next version.


All times are GMT -4. The time now is 10:15 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC