Monday, April 8, 2013

jquery on focus change background color AND onfocus select all text OR input text select all on focus

In the previous post i had shown how to select All text of the control and continuing the post now i will show change border color of the focused control as shown below.........
and this works for textbox, dropdownlist, listbox, textarea ...

Out Put :
 CSS for for color :

 Place this CSS in a *.CSS file
 

textarea:focus
input[type="text"]:focus
input[type="password"]:focus
input[type="datetime"]:focus
input[type="datetime-local"]:focus,
input[type="date"]:focus
input[type="month"]:focus
input[type="time"]:focus
input[type="week"]:focus
input[type="number"]:focus
input[type="email"]:focus
input[type="url"]:focus
input[type="search"]:focus
input[type="tel"]:focus
input[type="color"]:focus
.uneditable-input:focus
{
    border-colorrgba(255, 17, 0, 0.8);
    outline0;
    outlinethin dotted \9/* IE6-9 */
    /*-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
    -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);*/
    -webkit-box-shadowinset 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(255, 0, 0, 0.6);
    -moz-box-shadowinset 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(255, 0, 0, 0.6);
    box-shadowinset 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(255, 0, 0, 0.6);
}

textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
input[type="color"],
.uneditable-input {
  background-color#ffffff;
  border1px solid #cccccc;
  -webkit-box-shadowinset 0 1px 1px rgba(0, 0, 0, 0.075);
     -moz-box-shadowinset 0 1px 1px rgba(0, 0, 0, 0.075);
          box-shadowinset 0 1px 1px rgba(0, 0, 0, 0.075);
  -webkit-transitionborder linear 0.2s, box-shadow linear 0.2s;
     -moz-transitionborder linear 0.2s, box-shadow linear 0.2s;
       -o-transitionborder linear 0.2s, box-shadow linear 0.2s;
          transitionborder linear 0.2s, box-shadow linear 0.2s;
}

select,
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
input[type="color"],
.uneditable-input {
  displayinline-block;
  height20px;
  padding4px 6px;
  margin-bottom10px;
  font-size14px;
  line-height20px;
  color#555555;
  vertical-alignmiddle;
  -webkit-border-radius4px;
     -moz-border-radius4px;
          border-radius4px;
}

and the script U required is 



    <script type="text/javascript">
        $(document).ready(function () {
            $('INPUT[type="text"]').focus(function () {
                $(this).addClass("focus");
            });
            $('INPUT[type="text"]').blur(function () {
                $(this).removeClass("focus");
            });
            $('SELECT, TEXTAREA').focus(function () {
                $(this).addClass("focus");
            });
            $('SELECT, TEXTAREA').blur(function () {
                $(this).removeClass("focus");
            });
        });
    </script>

No comments:

Post a Comment