Skip to content
Advertisement

How to make background of a textbox with a if condition

I have below input text field.

JavaScript

I need to change the background color of this textbox according to the text. From below code, I could get this done after clicking on the box.

JavaScript

Here is my CSS class.

JavaScript

But I need to show the red color border without clicking. Further I need to change the background also to red color.

This textbox is inside a popup window. I need when someone opens the popup, to show red highligheted.

Can someone help me to improve my code?

update:

Here is the button which I use to open the dialog box.

JavaScript

Here is the ajax class

JavaScript

Advertisement

Answer

I think all you need to change is to move $(this).addClass("focused"); outside the $("#user_status").focus(function(){ event handler, so you’re not waiting for the textbox to be focused before adding the class – and it’s the same when removing the class. Therefore you don’t need the “focus” and “blur” event handlers at all:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement