Jump to content

how can I Change text box color if field is blank?


atrum

Recommended Posts

Ok. so, I am still a little new at javascript, and I need to know how to create a function that does the following.

 

if field == blank

change.textbox.color= somecolor

else

move onto the next field and repeat the check on the next field.

 

 

I know how to display an alert popup box if a field is blank. I just need the part that calls the field object.

 

Can any one help me on this?

 

Also, if what I asked doesn't make sense, please tell me and I can try and explain it differently.

 

Thanks.

Hey, I thought your problem was quite intruiging so I had a go and came up with this:

 

<html>
<head>
<script type="text/javascript">
function change()
{
var input = document.getElementById('input');
if(input.value == '')
{
	input.style.background = 'red';
}
else
{
	input.style.background = '';
}
}
</script>
</head>
<body onload="change()">
<input id="input" type="text" onkeyup="change()" />
</body>
</html>

 

Now, considering I'm a bit of a javascript noob, I'm quite proud of this :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.