By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,644 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Changing fontcolor in formfield

P: n/a
Joe
having this script:
-------------------------------------------------------------------
<script language="JavaScript" type="text/javascript">
<!--
function isanumber()
{
var antal = document.insert.antal.value;
var isanumber = /^[0-9]+$/;
if(isanumber.test(antal))
{
ready = true;
}
else
{
document.forms.insert.antal.focus();
document.forms.insert.antal.value = "insert a number";
ready = false;
}
return ready;
}
-->
</script>
-------------------------------------------------------------------

I would like to change the fontcolor in the inputfield to red when the
function returns FALSE.Can this be done, and if, how??

Joe
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Joe" <am***********@hotmail.com> schreef in bericht
news:3f***********************@dread11.news.tele.d k...
having this script:
-------------------------------------------------------------------
<script language="JavaScript" type="text/javascript"> .... </script>
-------------------------------------------------------------------

I would like to change the fontcolor in the inputfield to red when the
function returns FALSE.Can this be done, and if, how??


<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function isanumber() {
var field = document.insert.antal;
var antal = field.value;
var isanumber = /^[0-9]+$/;
var ready = isanumber.test(antal);

if (!ready) {
field.focus();
field.value = "insert a number";
field.style.color = 'red';
// Optional; Change the font color back to black when new
// data is entered into the field
field.onkeypress = field.onpaste = function () { this.style.color =
'black' }
}
return ready;
}

</script>
</head>

<body>
<form onsubmit="return isanumber()" name=insert>
<input type=text name=antal><input type=submit>
</form>
</body>
</html>
JW

Jul 20 '05 #2

P: n/a
Joe
Thanx, that really did the trick

Joe
"Janwillem Borleffs" <jw*@jwbfoto.demon.nl> wrote in message
news:3f***********************@news.euronet.nl...

"Joe" <am***********@hotmail.com> schreef in bericht
news:3f***********************@dread11.news.tele.d k...
having this script:
-------------------------------------------------------------------
<script language="JavaScript" type="text/javascript">

...
</script>
-------------------------------------------------------------------

I would like to change the fontcolor in the inputfield to red when the
function returns FALSE.Can this be done, and if, how??


<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function isanumber() {
var field = document.insert.antal;
var antal = field.value;
var isanumber = /^[0-9]+$/;
var ready = isanumber.test(antal);

if (!ready) {
field.focus();
field.value = "insert a number";
field.style.color = 'red';
// Optional; Change the font color back to black when new
// data is entered into the field
field.onkeypress = field.onpaste = function () { this.style.color =
'black' }
}
return ready;
}

</script>
</head>

<body>
<form onsubmit="return isanumber()" name=insert>
<input type=text name=antal><input type=submit>
</form>
</body>
</html>
JW

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.