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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.