473,378 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Multicoloured text in INPUT elements?

I guess the subject says it all, really, and I know it's
not a standard of the feature-set, but has anyone
experimented with it?

I'm writing an autocompleting INPUT element and
would like it to display its choice based on the current
text but in a different colour. I'm sure this could be
done with transparent layers, but I haven't looked into
it and would be interested to hear anyone else's
experiences (may save me from reinventing the
wheel).

Thankya kindly.

Nov 1 '06 #1
6 1552
ASM
Rancid Buttchutney a écrit :
I'm writing an autocompleting INPUT element and
would like it to display its choice based on the current
text but in a different colour. I'm sure this could be
done with transparent layers, but I haven't looked into
it and would be interested to hear anyone else's
experiences (may save me from reinventing the
wheel).
<style type="text/css">
input.green { background: lime }
input.blue { background: skyblue }
input { background: lightyellow }
input:hover, input.ieOver { background: yellow }
input:focus, input.ieOn { background: gold }
</style>
<script type="text/javascript">
function backColor(what) {
if(what.value.length<1) what.className='';
else if((what.value)*1) what.className='green';
else what.className = 'blue';
}
var IE = false; /*@cc_on IE=true; @*/
onload = function() {
var I = document.getElementsByTagName('input');
for(var i=0; i<I.length; i++)
if(I[i].type == 'text') {
I[i].onchange = function(){backColor(this);}
if(IE) {
I[i].onmouseover = function(){this.className='ieOver';}
I[i].onmouseout = function(){backColor(this);}
I[i].onfocus = function(){this.className='ieOn';}
I[i].onblur = function(){backColor(this);}
}
}
}
</script>

tested with FireFox; Opera, IE Mac
Nov 1 '06 #2
ASM wrote on 01 nov 2006 in comp.lang.javascript:
var IE = false; /*@cc_on IE=true; @*/
onload = function() {
var I = document.getElementsByTagName('input');
for(var i=0; i<I.length; i++)
if(I[i].type == 'text') {
I[i].onchange = function(){backColor(this);}
IE will be happy with css like this:

input { background-color:expression(value!=defaultValue?"cyan":"");}

Which can be very useful for serverside database management
in webmaster only pages, where IE only is not so terrible,
and otherwise the above degrades nicely to not working.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 1 '06 #3
ASM
Evertjan. a écrit :
ASM wrote on 01 nov 2006 in comp.lang.javascript:
>var IE = false; /*@cc_on IE=true; @*/
onload = function() {
var I = document.getElementsByTagName('input');
for(var i=0; i<I.length; i++)
if(I[i].type == 'text') {
I[i].onchange = function(){backColor(this);}

IE will be happy with css like this:

input { background-color:expression(value!=defaultValue?"cyan":"");}
in my example the IE instructions are for pseudo-classes
:focus and :hover

would it be possible to have an expression for these ones ?
Which can be very useful for serverside database management
in webmaster only pages, where IE only is not so terrible,
and otherwise the above degrades nicely to not working.
Nov 1 '06 #4
ASM wrote on 02 nov 2006 in comp.lang.javascript:
>IE will be happy with css like this:

input { background-color:expression(value!=defaultValue?"cyan":"");}

in my example the IE instructions are for pseudo-classes
>:focus and :hover

would it be possible to have an expression for these ones ?
Possible yes, usefull no:

<script type='text/javascript'>
var hov;
</script>
<style>
input { background-color:expression(hov=="over"?"cyan":"");}
</style>
<input onmouseover = 'hov="over"' onmouseout = 'hov = "out"'>

IE7 tested

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 1 '06 #5
Evertjan. wrote:
input { background-color:expression(value!=defaultValue?"cyan":"");}
Which can be very useful for serverside database management
in webmaster only pages, where IE only is not so terrible,
and otherwise the above degrades nicely to not working.
Be careful with expressions, though. They get re-evaluated constantly, even
with mouse moves. I once wrote an app that used expressions almost exactly
like the above, to automatically highlight unfilled fields. Worked great,
but it also caused the system to slow down a lot on big forms. I went back
to the "old" way, and now I only use expressions when absolutely necessary.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 2 '06 #6
Matt Kruse wrote on 02 nov 2006 in comp.lang.javascript:
Evertjan. wrote:
>input { background-color:expression(value!=defaultValue?"cyan":"");}
Which can be very useful for serverside database management
in webmaster only pages, where IE only is not so terrible,
and otherwise the above degrades nicely to not working.

Be careful with expressions, though. They get re-evaluated constantly,
even with mouse moves. I once wrote an app that used expressions
almost exactly like the above, to automatically highlight unfilled
fields. Worked great, but it also caused the system to slow down a lot
on big forms. I went back to the "old" way, and now I only use
expressions when absolutely necessary.
Used only for my own benefit in my webmaster only pages,
I love theis perhaps quick and dirty solution.

If my pc slows down clientside, I will take measures, Matt,
but with upto say 30 input fields, I never felt the problem.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mikko Rantalainen | last post by:
See example at <URL:http://www.cc.jyu.fi/~mira/moz/formtest.php>. The problem is that the label of submit button is always centered on the button regardsless of 'text-align' property in CSS....
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
7
by: Marios Koumides | last post by:
I post the same question few days ago but there was a confusion in the answers. Anywayz I am posting again. I have a form with 96 textboxes (8 rows x 12 columns) Now I want in the last row to have...
12
by: Randell D. | last post by:
Folks, I have a form called "ourTestForm". Its a test form - nothing special - it contains five input tags - they are named one, two, three, four and five. The input tags are of type...
17
by: wolfing1 | last post by:
Like, I know if several checkboxes have the same name, I can get the ones that were checked after submit with a request.form("name") and maybe do a split(request.form("name"),",") to cycle through...
1
by: daldridge | last post by:
I have a unique-elements/sorting question (who doesn't?), but haven't yet been able to get appropriate template/select/for-each processing working. I don't fully grok the Muenchian technique yet...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
3
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.