0

I am dynamically modifying a textfield using Javascript by adding some extra character (say X). For this I use:

document.forms['Form1'].elements['some_field'].value = document.forms['Form1'].elements['some_field'].value + "X";

But can I change the color of "X"? Like have it insert (say) a Red colored "X".

5
  • possible duplicate of formating part of text inside a textfield Commented Nov 7, 2011 at 1:52
  • Just the X? I don't believe so. You could put something next to the field, though. Commented Nov 7, 2011 at 1:52
  • Yes. Essentially I am adding some noise to the textfield and want it to be displayed in a different color. @Felix: I think this is different, since I am adding text dynamically using JS. Commented Nov 7, 2011 at 1:54
  • It's still not possible ;) Whether the value is static or dynamic does not matter. Commented Nov 7, 2011 at 1:55
  • 1
    @Titan How it gets there isn't really relevant, I just don't think you can do that with a text input. Commented Nov 7, 2011 at 1:55

1 Answer 1

2

You can use a contenteditable span and make it look like a text box.

HTML:

<span contenteditable="true" id="main"></span>

JavaScript:

document.getElementById("main").innerHTML += "<span style=\"color:red\">X</span>";

(optional) CSS Styling

#main {
    appearance: textfield;
    -moz-appearance: textfield;
    -webkit-appearance: textfield;
    height: 20px;
    width: 160px;
}

Demo: http://jsfiddle.net/TnUQW/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.