locked
how to chnage color of image button when text entered in textbox using javascript RRS feed

  • Question

  •  i have a textbox and two image buttons in form,initially the image button is in blue color when the text is entered in the textbox the button should change to redcolor(other image button),reply soon,thanks on advance

    Tuesday, November 2, 2010 9:24 AM

All replies

  • Hi,

    Please find your answer. I have used jQuery---

    <input type="text" id="txt"/>
    <input type="button" name="test" id="btn2" value="Button 2" style="background-color:blue"/>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery("#txt").keyup(function() {
                if (jQuery(this).val().length > 0)
                    jQuery("#btn2").css("background-color", "red");
                else
                    jQuery("#btn2").css("background-color", "blue");
            });
        });
    </script>


    Thanks AnupDG
    • Proposed as answer by AnupDG Thursday, November 4, 2010 12:22 PM
    Thursday, November 4, 2010 12:21 PM