Changing fontcolor in formfield

J

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
 
J

Janwillem Borleffs

Joe said:
having this script:

<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
 
J

Joe

Thanx, that really did the trick

Joe


Janwillem Borleffs said:
Joe said:
having this script:

<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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top