Say I wanted to color in only part of a user's text in an input field (for instance, making a single invalid word turn red). Is this possible to do, considering that there is no innerHTML?
Cool, thanks.For what it's worth you can take a look at one of the scripts (Masked Input) I've put together for this type of thing. It doesn't do exactly what you're wanting, but may give you some inspiration at the least and you can make use of my code if that helps too.
Note though that the effects I use in my examples aren't directly linked on the page so you'll have to dig through the source to get to them. The JavaScript files you'll want to look at are shakeshake.js and the end of masked_input_ex.js. Also, I haven't thoroughly tested out the script in various browsers, but I think it does pretty well.
That's a great real time validation script, and is a common means to control form input on alot of sites. Thanks for posting the link, angelwatt.
To do exactly what the OP wants, change color of specific characters and not just the entire text or background color, border, etc., is indeed very tricky. Here's my conceptualized shot at it:
One way is to create an empty div right next to the input field with CSS that makes it look exactly the same as your blank input text field, but set display: none. After the appropriate event is triggered (OnKeyUp, OnClick, onBlur as you wish) call a JS function that reads the input field value into a string, validate and add in HTML as you see fit (colorizing characters, etc.). The copy that string to the div's innerHTML, disable the input field temporarily, and position the div exactly where the input field was and change display to inline or whatever you wish so that its visible. Then after an OnClick or whatever event trigger you prefer, call another function which strips the HTML and copies the plain text back into the input field, then re-enable it and change the div display back to none. If you want to get fancy, there are ways to preserve the original cursor position within the input field and re-position the cursor as part of the last step.
Needless to say, it involves alot of extra work, numerous event triggers in some rather complex JS, it's still the same basic masking technique but cosmetically enhanced.
Personally, a ton of work and doing the masking method angelwatt posted is just as user friendly and intuitive if you ask me. But I posted the "concept" to show you a possible means, which would require alot of testing and heavy thought, I'm sure.
Oh yeah, don't ask me for example code - I made all this up, and never tried it before, so if I disuaded you from trying, maybe that's good, too!
-jim
That's a great real time validation script, and is a common means to control form input on alot of sites. Thanks for posting the link, angelwatt.![]()
I realized that whenever you had text that went beyond the width of the text input area, it would become absurdly complicated.
My other alternative would be writing an alternative text entry form from scratch, which seems pretty crazy too.
Hmm....
I've never looked into something like this so it might not be available, but have you looked at JavaScript libraries such as the Dojo Toolkit at all? They have some fantastic stuff done in JavaScript that really does save a lot of time.
Awesome suggestion, Cromulent!!!
I visited the site, found this related demo using their framework:
http://demos.dojotoolkit.org/demos/form/
@OP: View the demo above, type in the letter A or something into the ZIP code field, for example, see what it does. Waaaaaay cool.
If you like it, the framework can be downloaded with documentation links here:
http://www.dojotoolkit.org/
Thank Cromulent, not me! I never heard of it, it's now on my list of tools! So with angelwatt's code and this, you've now got choices, and should be GTG!
-jim
Ok, I went with a similar style to that with an error message that explains what's going on.
Thanks for the help, everyone.![]()