atrum Posted March 15, 2009 Share Posted March 15, 2009 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 https://forums.phpfreaks.com/topic/149541-how-can-i-change-text-box-color-if-field-is-blank/ Share on other sites More sharing options...
jackpf Posted March 15, 2009 Share Posted March 15, 2009 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 Link to comment https://forums.phpfreaks.com/topic/149541-how-can-i-change-text-box-color-if-field-is-blank/#findComment-785326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.