Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the below code.

I have an input text field which has an example value grey colored. When clicking on the field, the text is erased and color is set to black. Then, after it finishes some VBScript, the fields are cleared and the example is back in the input field, but I cannot get it to also color it grey at this point.

Everything works fine except UserName.style = "color: #ccc;" in the VBScript.

Am I missing something here? VB error says "Not implemented"

Any solution highly appreciated. Thank you.

VBScript:

UserName.value = "Example: JSmith"
UserName.style = "color: #ccc;"
</SCRIPT>

HTML:

<input type="text" name="UserName" value="Example: JSmith" style="color: #ccc;"  onfocus="myFunction(UserName)"><p>

JavaScript:

function myFunction(x)
{
x.style.color="black";
x.value="";
}
share|improve this question
 
try UserName.setAttribute "style", "color: #ccc;" –  ultima_rat0 May 20 at 23:06
 
I assume you mean asp.net? –  JohnFx May 20 at 23:06
 
how about #cccccc ... –  matzone May 21 at 2:56
 
tried UserName.setAttribute "style", "color: #ccc;" with both #ccc and #cccccc. Error message no longer displayed but font does not change to #ccc –  AdrianM May 21 at 10:27
add comment

2 Answers

VBScript/.HTA demo:

<html>
 <head>
  <Title>colortext</Title>
  <hta:application id="colortext" scroll = "no">
  <script type="text/vbscript">
   Function CBT()
     ' change backgound color of txtDemo
     Dim txtDemo : Set txtDemo = document.getElementById("txtDemo")
     Select Case txtDemo.style.backgroundColor
       Case "black"
         txtDemo.style.backgroundColor = "yellow"
       Case "yellow"
         txtDemo.style.backgroundColor = "red"
       Case Else
         txtDemo.style.backgroundColor = "black"
     End Select
   End Function
  </script>
 </head>
 <body>
  <input type="text" id="txtDemo" value="Initial Value" />
  <hr />
  <input type="button" value="CBT" onclick="CBT" />
 </body>
</html>

The important part is to get the HTML element document.getElementById("txtDemo") and its .style.backgroundColor property.

share|improve this answer
 
Not really what I wanted. The font color needs to change on focus and revert back when the script is finished. I figured out the solution, will post it in a sec. Thanks! –  AdrianM May 21 at 12:48
add comment

VBScript:

Call initialColor()
UserName.value = "Example: JSmith"

HTML:

<input type="text" name="UserName" value="Example: JSmith" style="color: #ccc;"  onfocus="myFunction(UserName)"><p>

JavaScript:

function changeColor(x)
{
x.style.color="black";
x.value="";
}
function initialColor()
{
UserName.style.color="ccc";
Manager.style.color="ccc";
Ticket.style.color="ccc";
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.